#include <tb_animated_sprite.hpp>
Public Member Functions | |
AnimatedSprite (const SpriteFrame &spriteFrame) | |
AnimatedSprite (const tbCore::tbString &textureFile, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0, const size_t &frameCount=1) | |
AnimatedSprite (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName) | |
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 |
bool | IsAnimationPlaying (const tbCore::tbString &sequenceName) const |
size_t | GetFrameIndex (void) const |
Public Member Functions inherited from TurtleBrains::Graphics::Sprite | |
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 tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName) | |
Sprite (const Sprite &other) | |
virtual | ~Sprite (void) |
Sprite & | operator= (const Sprite &other) |
virtual PixelSpace | GetPixelWidth (void) const override |
virtual PixelSpace | GetPixelHeight (void) const override |
void | SetFlippedHorizontally (bool isFlippedHorizontally) |
void | SetFlippedVertically (bool isFlippedVertically) |
bool | IsFlippedHorizontally (void) const |
bool | IsFlippedVertically (void) const |
Public Member Functions inherited from TurtleBrains::Graphics::Graphic | |
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) |
const tbMath::Vector2 & | GetOrigin (void) const |
void | SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) |
void | SetOrigin (const float originX, const float originY) |
void | SetOrigin (const tbMath::Vector2 &origin) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
const tbMath::Vector2 & | GetScale (void) const |
void | SetScale (const float scale) |
void | SetScale (const tbMath::Vector2 &scale) |
void | SetScale (const float scaleX, const float scaleY) |
float | GetRotation (void) const |
void | SetRotation (const float rotation) |
void | SetScroll (const float scroll) |
void | SetScroll (const float scrollX, const float scrollY) |
bool | IsRelative (void) const |
const Color & | GetColor (void) const |
virtual void | SetColor (const tbGraphics::Color &newColor) |
float | GetWidth (void) const |
float | GetHeight (void) const |
float | GetScaledWidth (void) const |
float | GetScaledHeight (void) const |
bool | UnstableIsPointContained (const tbMath::Vector2 &point) const |
Static Public Member Functions | |
static void | SetAnimationFrameRate (const int framesPerSecond) |
Static Public Attributes | |
static const float & | kDefaultTimePerFrame |
Protected Member Functions | |
virtual void | OnUpdate (const float deltaTime) override |
Protected Member Functions inherited from TurtleBrains::Graphics::Sprite | |
virtual void | OnRender (void) const override |
void | SetSpriteFrame (const SpriteFrame &spriteFrame) |
const SpriteFrame & | GetSpriteFrame (void) const |
Protected Member Functions inherited from TurtleBrains::Graphics::Graphic | |
virtual void | ApplyTransform (void) const |
virtual void | PopTransform (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 tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteName | ||
) |
Creates an AnimatedSprite similar to AnimatedSprite(tbGraphics::theSpriteManager.GetAnimatedSprite("sheet", "sprite")) except more convenient.
spriteSheetName | A name to a SpriteSheet that was loaded during a call to SpriteManager::LoadSpriteSheetFromFile() or SpriteManager::LoadSpriteSheetFromData(). If no SpriteSheet is found with the provided spriteSheetName, an error condition will be triggered. |
spriteName | A name to the sprite data on the specified SpriteSheet which was loaded. If no sprite data is found with the provided spriteName and error condition will be triggered. |
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 |
Returns the index of the current frame. This function may be removed or changed in future versions of the framework.
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::IsAnimationPlaying | ( | const tbCore::tbString & | sequenceName | ) | const |
Checks if a specific animation sequence matches the current sequence and that it is currently playing. True will be returned only if the sequence matches AND the animation is in playing state so not stopped or at the end of a non-looping, otherwise false indicates the sequence does not match or animation stopped.
sequenceName | The name of the sequence to check if it is the one playing. |
|
overrideprotectedvirtual |
If the animation is playing 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(). |
|
static |
Sets the default framerate for the AnimatedSprites to use, by default this is set to 30fps.
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.