#include <tb_animated_sprite.h>
Public Member Functions | |
AnimatedSprite (const SpriteFrame &spriteFrame) | |
AnimatedSprite (const AnimatedSprite &other) | |
AnimatedSprite & | operator= (const AnimatedSprite &other) |
virtual | ~AnimatedSprite (void) |
void | AddSequence (const tbCore::tbString &sequenceName, const AnimationSequence &sequence) |
void | AddMappedSequence (const tbCore::tbString &sequenceName, const SpriteMap &spriteMap, const std::vector< size_t > frames) |
void | AddMappedSequence (const tbCore::tbString &sequenceName, const SpriteMap &spriteMap, const size_t &startFrameIndex, const size_t &frameCount) |
void | PlayAnimation (const tbCore::tbString &sequenceName, const bool isLooping, const bool isForward=true, const float timePerFrame=kDefaultTimePerFrame) |
void | PlayAnimation (const tbCore::tbString &sequenceName) |
void | StopAnimation (void) |
bool | IsAnimationPlaying (void) const |
size_t | GetFrameIndex (void) const |
bool | IsPlayingAnimation (const tbCore::tbString &sequenceName) const |
![]() | |
Sprite (const SpriteFrame &spriteFrame) | |
Sprite (const tbCore::tbString &textureFile, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0) | |
Sprite (const TextureHandle &textureHandle, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0) | |
Sprite (const Sprite &other) | |
virtual | ~Sprite (void) |
Sprite & | operator= (const Sprite &other) |
void | SetOrigin (const AnchorLocation &anchor) |
void | SetOrigin (const float originX, const float originY) |
void | SetScale (const float scale) |
void | SetScale (const float scaleX, const float scaleY) |
void | SetRotation (const float rotation) |
![]() | |
Graphic (void) | |
Graphic (const Graphic &other) | |
virtual | ~Graphic (void) |
bool | IsActive (void) const |
void | SetActive (const bool isActive) |
void | Update (const float deltaTime) |
bool | IsVisible (void) const |
void | SetVisible (const bool isVisible) |
void | Render (void) const |
const tbMath::Vector2 & | GetPosition (void) const |
void | SetPosition (const float x, const float y) |
void | SetPosition (const tbMath::Vector2 &position) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
bool | IsRelative (void) const |
virtual void | SetColor (const tbGraphics::Color &newColor) |
Static Public Attributes | |
static const float | kDefaultTimePerFrame |
Protected Member Functions | |
virtual void | OnUpdate (const float deltaTime) override |
![]() | |
virtual void | OnRender (void) const override |
void | SetSpriteFrame (const SpriteFrame &spriteFrame) |
const SpriteFrame & | GetSpriteFrame (void) const |
![]() | |
const Color & | GetColor (void) const |
The AnimatedSprite is a Sprite that contains several AnimationSequences that can be played back to flip the frames of the sprite to playback an animation.
|
explicit |
Creates an AnimatedSprite with a given sprite frame, all frames of the sequences added to the AnimatedSprite must have the same texture handle as this frame or an error condition will be triggered.
spriteFrame | the initial frame of the Sprite containing the TextureHandle that all other frames must have in order to be used. |
TurtleBrains::Graphics::AnimatedSprite::AnimatedSprite | ( | const AnimatedSprite & | other | ) |
Copy constructor to create an animated sprite by copying all sequences from the other object.
other | The AnimatedSprite to copy and mimic. |
|
virtual |
Destructs the AnimatedSprite object cleaning up the sequences of animations that had been added.
void TurtleBrains::Graphics::AnimatedSprite::AddMappedSequence | ( | const tbCore::tbString & | sequenceName, |
const SpriteMap & | spriteMap, | ||
const std::vector< size_t > | frames | ||
) |
Creates an AnimationSequence with the parameters given, literally calling the appropriate constructor. This may be removed from the interface in future versions as it is redundant now. Should favor the use of loading json Sprite Sheets in the SpriteManager with animation and sprite data.
sequenceName | A name for the animation sequence added so it can be reference later in PlayAnimation using the same name. Must not be an empty string or an error condition will occur, must be different than any other sequence that has been added to the animated sprite or an error condition will be triggered. |
spriteMap | The SpriteMap object describing the location and framesize of each frame in the animation. |
frames | is an ordered container of the frames in the sequences, { 0, 1, 5, 3 }. |
void TurtleBrains::Graphics::AnimatedSprite::AddMappedSequence | ( | const tbCore::tbString & | sequenceName, |
const SpriteMap & | spriteMap, | ||
const size_t & | startFrameIndex, | ||
const size_t & | frameCount | ||
) |
Creates an AnimationSequence with the parameters given, literally calling the appropriate constructor. This may be removed from the interface in future versions as it is redundant now. Should favor the use of loading json Sprite Sheets in the SpriteManager with animation and sprite data.
sequenceName | A name for the animation sequence added so it can be reference later in PlayAnimation using the same name. Must not be an empty string or an error condition will occur, must be different than any other sequence that has been added to the animated sprite or an error condition will be triggered. |
spriteMap | The SpriteMap object describing the location and framesize of each frame in the animation. |
startFrameIndex | The first frame of the ordered sequence. |
frameCount | The number of frames in the sequence, the final frame index will be startFrame + frameCount. |
void TurtleBrains::Graphics::AnimatedSprite::AddSequence | ( | const tbCore::tbString & | sequenceName, |
const AnimationSequence & | sequence | ||
) |
Adds a set of frames to the AnimatedSprite so it can be played as an animation using PlayAnimation(). It is expected that no AnimationSequence has been added with sequenceName and that the sequence has no more than 256 frames of animation or an error condition will be triggered.
sequenceName | A name for the animation sequence added so it can be reference later in PlayAnimation using the same name. Must not be an empty string or an error condition will occur, must be different than any other sequence that has been added to the animated sprite or an error condition will be triggered. |
sequence | The sequence of frames that represents the animation. |
|
inline |
TODO: TIM: Documentation: Teach the user how to use this.
bool TurtleBrains::Graphics::AnimatedSprite::IsAnimationPlaying | ( | void | ) | const |
Check if the animation is currently playing or if it has reached the end and stopped, or been stopped with a call to StopAnimation(). This will always return true for a looping animation!
bool TurtleBrains::Graphics::AnimatedSprite::IsPlayingAnimation | ( | const tbCore::tbString & | sequenceName | ) | const |
TODO: TIM: Documentation: Teach the user how to use this.
|
overrideprotectedvirtual |
If the animation is paying this will update the frame timers and swap to the next frame if the timer has exceeded the maximum time allowed per frame.
Reimplemented from TurtleBrains::Graphics::Graphic.
AnimatedSprite& TurtleBrains::Graphics::AnimatedSprite::operator= | ( | const AnimatedSprite & | other | ) |
Assignment operator for the AnimatedSprite, this will clear any current animation and sequences, copy all the sequences from the other object and set the current frame and timers to that other object.
other | The AnimatedSprite to copy and mimic. |
void TurtleBrains::Graphics::AnimatedSprite::PlayAnimation | ( | const tbCore::tbString & | sequenceName, |
const bool | isLooping, | ||
const bool | isForward = true , |
||
const float | timePerFrame = kDefaultTimePerFrame |
||
) |
Sets the current sequence to the one found by the sequenceName, the sprite is immediately changed to the first frame of the sequence, or last if played backwards, and the animation begins the frame timers.
sequenceName | The name of the sequence to play, as it was added in AddSequence(). |
isLooping | Set to true to play a looping animation until either StopAnimation() is called, or another animation is started with PlayAnimation(). |
isForward | Set to true to play the animation forward, or false to start from the last frame and play backward until the first frame is reached. |
timePerFrame | Sets the minimum amount of time that a frame should be displayed for before changing to the next frame of the animation. This may be changing to milliseconds in the future, but currently the value is in seconds where 1.25 is one and a quarter seconds per frame. |
void TurtleBrains::Graphics::AnimatedSprite::PlayAnimation | ( | const tbCore::tbString & | sequenceName | ) |
Sets the current sequence to the one found by the sequenceName, the sprite is immediately changed to the first frame of the sequence, or last if played backwards, and the animation begins the frame timers.
sequenceName | The name of the sequence to play, as it was added in AddSequence(). |
void TurtleBrains::Graphics::AnimatedSprite::StopAnimation | ( | void | ) |
Stops the animation on the current frame and stops the frame timers from being processed further. No frames will be switched until PlayAnimation is called again to begin playing.
|
static |
The default amount of time per frame, in seconds by the animation system. Currently at 30fps in (TurtleBrains v0.2.0). This may become an integer type that represents the time in milliseconds.