TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
TurtleBrains::Graphics::AnimatedSprite Class Reference

#include <tb_animated_sprite.h>

Inheritance diagram for TurtleBrains::Graphics::AnimatedSprite:
TurtleBrains::Graphics::Sprite TurtleBrains::Graphics::Graphic

Public Member Functions

 AnimatedSprite (const SpriteFrame &spriteFrame)
 
 AnimatedSprite (const AnimatedSprite &other)
 
AnimatedSpriteoperator= (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
 
- 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 Sprite &other)
 
virtual ~Sprite (void)
 
Spriteoperator= (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)
 
- 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::Vector2GetPosition (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
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Sprite
virtual void OnRender (void) const override
 
void SetSpriteFrame (const SpriteFrame &spriteFrame)
 
const SpriteFrameGetSpriteFrame (void) const
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
const ColorGetColor (void) const
 

Detailed Description

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.

Constructor & Destructor Documentation

TurtleBrains::Graphics::AnimatedSprite::AnimatedSprite ( const SpriteFrame spriteFrame)
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.

Parameters
spriteFramethe 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.

Parameters
otherThe AnimatedSprite to copy and mimic.
virtual TurtleBrains::Graphics::AnimatedSprite::~AnimatedSprite ( void  )
virtual

Destructs the AnimatedSprite object cleaning up the sequences of animations that had been added.

Member Function Documentation

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.

Parameters
sequenceNameA 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.
spriteMapThe SpriteMap object describing the location and framesize of each frame in the animation.
framesis 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.

Parameters
sequenceNameA 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.
spriteMapThe SpriteMap object describing the location and framesize of each frame in the animation.
startFrameIndexThe first frame of the ordered sequence.
frameCountThe 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.

Parameters
sequenceNameA 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.
sequenceThe sequence of frames that represents the animation.
size_t TurtleBrains::Graphics::AnimatedSprite::GetFrameIndex ( void  ) const
inline

TODO: TIM: Documentation: Teach the user how to use this.

Note
This was added during LD32 as a quick hack and may or may not be removed. Use at your own risk.
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.

Note
This was added during LD32 as a quick hack and may or may not be removed. Use at your own risk.
virtual void TurtleBrains::Graphics::AnimatedSprite::OnUpdate ( const float  deltaTime)
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.

Parameters
otherThe 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.

Parameters
sequenceNameThe name of the sequence to play, as it was added in AddSequence().
isLoopingSet to true to play a looping animation until either StopAnimation() is called, or another animation is started with PlayAnimation().
isForwardSet to true to play the animation forward, or false to start from the last frame and play backward until the first frame is reached.
timePerFrameSets 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.
Note
timePerFrame may become a time in milliseconds with a maximum of 100 frames per second and a minimum of 1 frame per second, although this is yet to be decided.
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.

Parameters
sequenceNameThe 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.

Note
The implementation details may change in the future pending the addition of a Pause(), if Pause() is introduced, Stop() will stop the animation and set the frame to the first frame of animation. This is yet to be decided. TODO: TIM: Implementation: Figure out this detail before TurtleBrains public release.

Member Data Documentation

const float TurtleBrains::Graphics::AnimatedSprite::kDefaultTimePerFrame
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.

Note
This may become a time in milliseconds with a maximum of 100 frames per second and a minimum of 1 frame per second, although this is yet to be decided.