stmm-games-doc  0.32.0
Classes | Public Member Functions | Protected Member Functions | List of all members
stmg::BackgroundAnimation Class Reference

Background animation. More...

Inheritance diagram for stmg::BackgroundAnimation:
Inheritance graph
[legend]

Classes

struct  Init
 

Public Member Functions

 BackgroundAnimation (const Init &oInit) noexcept
 Constructor. More...
 
int32_t getImageId () const noexcept
 The current image id. More...
 
FPoint getImageRelPos () const noexcept
 The current relative position of the image within the animation rectangle. More...
 
FSize getImageSize () const noexcept
 The size of the image. More...
 
void setImage (int32_t nImgId, const FSize &oNewSize, const FPoint &oImgRelPos) noexcept
 Set the repeated image to fill the animation rectangle. More...
 
void moveImageTo (const FPoint &oNewRelPos) noexcept
 Sets the new relative position of the pattern origin. More...
 
FPoint getImageRelPos (int32_t nViewTick, int32_t nTotViewTicks) const noexcept
 The position of the image origin within animation during view ticks. More...
 
void boardAfterScroll (Direction::VALUE eDir) noexcept
 
- Public Member Functions inherited from stmg::LevelAnimation
virtual ~LevelAnimation () noexcept=default
 
int32_t getId () const noexcept
 Returns unique Id of this object. More...
 
bool isActive () const noexcept
 Whether the animation was added to the level (and not removed yet). More...
 
int32_t getViewAnimationNameIdx () const noexcept
 The optional view animation name index. More...
 
REFSYS getRefSys () noexcept
 The reference system of the animation. More...
 
FPoint getPos () const noexcept
 The current position of the animation within its reference system. More...
 
FSize getSize () const noexcept
 The size of the animation. More...
 
int32_t getZ () const noexcept
 The depth of the animation. More...
 
double gameInterval () const noexcept
 The current game interval. More...
 
double getDuration () const noexcept
 The duration in milliseconds. More...
 
void moveTo (FPoint oPos) noexcept
 Sets new position within reference system. More...
 
void moveTo (int32_t nZ) noexcept
 Sets new position within reference system. More...
 
virtual void onScrolled (Direction::VALUE eDir) noexcept
 Called by Level when the animation is scrolled by Level::boardScroll. More...
 
double getElapsed (int32_t nViewTick, int32_t nTotViewTicks) const noexcept
 The time elapsed since the animation was started in milliseconds. More...
 
bool isStarted (int32_t nViewTick, int32_t nTotViewTicks) const noexcept
 Whether the animation has already started. More...
 
bool isDone (int32_t nViewTick, int32_t nTotViewTicks) const noexcept
 Whether the animation has finished. More...
 
Levellevel () noexcept
 The level. More...
 
const Levellevel () const noexcept
 The level. More...
 
GameProxygame () noexcept
 The game. More...
 
const GameProxygame () const noexcept
 The game. More...
 

Protected Member Functions

void reInit (const Init &oInit) noexcept
 See constructor. More...
 
- Protected Member Functions inherited from stmg::LevelAnimation
 LevelAnimation (const Init &oInit) noexcept
 Constructor. More...
 
void reInit (const Init &oInit) noexcept
 Reinitialization. More...
 

Additional Inherited Members

- Public Types inherited from stmg::LevelAnimation
enum  REFSYS { REFSYS_BOARD = -3, REFSYS_SHOW = -2, REFSYS_INVALID = -1, REFSYS_SUBSHOW = 0 }
 Reference system extended enumeration. More...
 
- Static Public Attributes inherited from stmg::LevelAnimation
static const double s_fDurationUndefined
 Undefined duration constant. More...
 
static const double s_fDurationInfinity
 Infinite duration constant. More...
 

Detailed Description

Background animation.

This animation has a fixed size within its reference system. Within the animation rectangle an image is used as pattern to fill it. The pattern origin (its top left corner) is set relative to the animation top left corner. The image id, position and size can change at runtime.

Constructor & Destructor Documentation

◆ BackgroundAnimation()

stmg::BackgroundAnimation::BackgroundAnimation ( const Init oInit)
explicitnoexcept

Constructor.

Parameters
oInitThe initialization parameters.

Member Function Documentation

◆ boardAfterScroll()

void stmg::BackgroundAnimation::boardAfterScroll ( Direction::VALUE  eDir)
noexcept

◆ getImageId()

int32_t stmg::BackgroundAnimation::getImageId ( ) const
inlinenoexcept

The current image id.

Returns
The image id or -1 if not set.

◆ getImageRelPos() [1/2]

FPoint stmg::BackgroundAnimation::getImageRelPos ( ) const
inlinenoexcept

The current relative position of the image within the animation rectangle.

Returns
The relative position in tiles.

◆ getImageRelPos() [2/2]

FPoint stmg::BackgroundAnimation::getImageRelPos ( int32_t  nViewTick,
int32_t  nTotViewTicks 
) const
noexcept

The position of the image origin within animation during view ticks.

Used to interpolate between current (game tick) position and the new (next game tick) position.

Parameters
nViewTickMust be >= 0 and < nTotViewTicks.
nTotViewTicksMust be > 0.
Returns
The intermediate relative position.

◆ getImageSize()

FSize stmg::BackgroundAnimation::getImageSize ( ) const
inlinenoexcept

The size of the image.

If one of the returned size components (oSize.m_fW and oNewSize.m_fH) is <= 0 the ratio of the natural size of the image should be used. If both oSize.m_fW and oSize.m_fH are <= 0 the natural size should be used.

Returns
The image size in tiles.

◆ moveImageTo()

void stmg::BackgroundAnimation::moveImageTo ( const FPoint oNewRelPos)
noexcept

Sets the new relative position of the pattern origin.

The new position is reached in a game tick interpolating the view tick position from the old position.

Parameters
oNewRelPosThe new relative position (in tiles).

◆ reInit()

void stmg::BackgroundAnimation::reInit ( const Init oInit)
protectednoexcept

See constructor.

◆ setImage()

void stmg::BackgroundAnimation::setImage ( int32_t  nImgId,
const FSize oNewSize,
const FPoint oImgRelPos 
)
noexcept

Set the repeated image to fill the animation rectangle.

If one of oNewSize.m_fW and oNewSize.m_fH is <= 0 the ratio of the natural size of the image should be used. If both oNewSize.m_fW and oNewSize.m_fH are <= 0 the the natural size should be used by the view.

Set the image to -1 to hide temporarily the animation.

Parameters
nImgIdThe image id. Must be valid id in `level().getNamed().images() or -1.
oNewSizeThe new size of the image.
oImgRelPosThe relative position of the image in respect to the position of the animation.