TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Graphics::AnimationSequence Class Reference

#include <tb_animated_sprite.hpp>

Public Member Functions

 AnimationSequence (const TextureHandle &textureHandle)
 
 AnimationSequence (const SpriteMap &spriteMap, const std::vector< size_t > &frames)
 
 AnimationSequence (const SpriteMap &spriteMap, const size_t &startFrameIndex, const size_t &frameCount)
 
 ~AnimationSequence (void)
 
void AddFrame (const SpriteFrame &frame)
 
void AddFrame (const PixelSpace &frameX, const PixelSpace &frameY, const PixelSpace &frameWidth, const PixelSpace &frameHeight)
 
size_t GetFrameCount (void) const
 
const SpriteFrameGetFrame (const size_t &frameIndex) const
 

Detailed Description

This is an ordered sequence of SpriteFrame objects that make up an animation for the AnimatedSprite to then flip from frame to frame.

Note
May eventually contain desired flip rate, default looping / pingpong values etc.

Constructor & Destructor Documentation

TurtleBrains::Graphics::AnimationSequence::AnimationSequence ( const TextureHandle textureHandle)
explicit

Creates an empty AnimationSequence with no frames. Frames must then be added to the sequence in the order desired by calling AddFrame().

Parameters
textureHandleAll frames added to the AnimationSequence must be on this texture.
Note
This will trigger an error condition it textureHandle is InvalidTexture().
TurtleBrains::Graphics::AnimationSequence::AnimationSequence ( const SpriteMap spriteMap,
const std::vector< size_t > &  frames 
)

Creates an AnimationSequence with a custom sequence of mapped frames by breaking down the texture into columns and rows based on width/height of the frame and texture, then uses the frames parameter as a sequence of indices into that space. A 512x256 texture, with a 32x32 frame will have 16 columns and 8 rows. The index 0 is for the top-left of the texture, the maximum index is (columns * rows) - 1 for the bottom-right most frame of the texture.

Parameters
spriteMapThe SpriteMap object describing the location and framesize of each frame in the animation.
framesThe customized sequence of indices on the mapped texture columns by rows, starting with top-left ending at the bottom-right.
TurtleBrains::Graphics::AnimationSequence::AnimationSequence ( const SpriteMap spriteMap,
const size_t &  startFrameIndex,
const size_t &  frameCount 
)

Creates an AnimationSequence with an ordered sequence of mapped frames by breaking down the texture into columns and rows based on width/height of the frame and texture, then uses the frames parameter as a sequence of indices into that space. A 512x256 texture, with a 32x32 frame will have 16 columns and 8 rows. The index 0 is for the top-left of the texture, the maximum index is (columns * rows) - 1 for the bottom-right most frame of the texture.

Parameters
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.
TurtleBrains::Graphics::AnimationSequence::~AnimationSequence ( void  )

Cleans up after the AnimationSequence by removing the sequence of SpriteFrame objects from memory.

Member Function Documentation

void TurtleBrains::Graphics::AnimationSequence::AddFrame ( const SpriteFrame frame)

Adds a single custom frame to the end of the sequence. Each frame will be played in the order added to the sequence. Call AddFrame(); in the order desired. It is possible to add the same frame multiple times as well for any desired effects.

Parameters
frameThe SpriteFrame object of the next frame in the animation sequence.
void TurtleBrains::Graphics::AnimationSequence::AddFrame ( const PixelSpace frameX,
const PixelSpace frameY,
const PixelSpace frameWidth,
const PixelSpace frameHeight 
)

Builds a SpriteFrame to add to the end of the sequence. Each frame will be played in the order added to the sequence. Call AddFrame(); in the order desired. It is possible to add the same frame multiple times as well for any desired effects.

Parameters
frameXThe horizontal pixel location of the left edge of the sprite frame, 0 is the left edge of texture.
frameYThe vertical pixel location of the top edge of the sprite frame, 0 is the top edge of texture.
frameWidthThe width in pixels of the sprite frame.
frameHeightThe height in pixels of the sprite frame.
const SpriteFrame& TurtleBrains::Graphics::AnimationSequence::GetFrame ( const size_t &  frameIndex) const

Returns the SpriteFrame at the frameIndex or triggers an error condition if frameIndex is out-of-range.

Parameters
frameIndexThe index of the SpriteFrame to return, must be in the range: (0 <= frameIndex < GetFrameCount()).
size_t TurtleBrains::Graphics::AnimationSequence::GetFrameCount ( void  ) const

Returns the number of frames in the AnimationSequence.