#include <tb_sprite_manager.h>
Public Member Functions | |
SpriteManager (void) | |
~SpriteManager (void) | |
bool | LoadSpriteSheetFromFile (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteSheetFile) |
TextureHandle | GetSpriteSheetTextureHandle (const tbCore::tbString &spriteSheetName) const |
SpriteFrame | GetSpriteFrame (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName) const |
Sprite | GetSpriteFromFile (const tbCore::tbString &textureFile, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0) const |
Sprite | GetSprite (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName) const |
AnimatedSprite | GetAnimatedSprite (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName) const |
void | AddAnimationSequences (const tbCore::tbString &spriteSheetName, const tbCore::tbString &spriteName, AnimatedSprite &animatedSprite) const |
The SpriteManager holds each of the SpriteSheets and all the Sprites and Animations that have been loaded into the manager. It provides an easy method of create a Sprite or AnimatedSprite object from data.
TurtleBrains::Graphics::SpriteManager::SpriteManager | ( | void | ) |
The SpriteManager should be treated like a singleton object and should only ever be accessed through the tbGraphics::theSpriteManager 'global' variable.
TurtleBrains::Graphics::SpriteManager::~SpriteManager | ( | void | ) |
The SpriteManager should be treated like a singleton object and should only ever be accessed through the tbGraphics::theSpriteManager 'global' variable.
void TurtleBrains::Graphics::SpriteManager::AddAnimationSequences | ( | const tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteName, | ||
AnimatedSprite & | animatedSprite | ||
) | const |
Adds all the AnimationSequences found on the spriteName to the animatedSprite provided.
spriteSheetName | A name to a SpriteSheet as loaded during a call to LoadSpriteSheetFromFile() or LoadSpriteSheetFromData(). If no object is found with the sheet name, 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. |
animatedSprite | The AnimatedSprite object to add the sequences to so they can be played back. |
AnimatedSprite TurtleBrains::Graphics::SpriteManager::GetAnimatedSprite | ( | const tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteName | ||
) | const |
Behaves identical to GetSprite() except an AnimatedSprite object is returned with AnimationSequences added to the AnimatedSprite, ready for action. An error condition is triggered if the sprite sheet is not found or the sprite data is not found. This can be called even if the sprite data does not contain any animation sequences, but as it is expected the sequences will be added upon initialization.
spriteSheetName | A name to a SpriteSheet as loaded during a call to LoadSpriteSheetFromFile() or LoadSpriteSheetFromData(). If no object is found with the sheet name, 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. |
Sprite TurtleBrains::Graphics::SpriteManager::GetSprite | ( | const tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteName | ||
) | const |
Creates a Sprite object from the data provided on the SpriteSheet for the given spriteName. If no SpriteSheet is found with the spriteSheetName, or if no sprite data is found with the spriteName an error condition will be triggered.
spriteSheetName | A name to a SpriteSheet as loaded during a call to LoadSpriteSheetFromFile() or LoadSpriteSheetFromData(). If no object is found with the sheet name, 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. |
SpriteFrame TurtleBrains::Graphics::SpriteManager::GetSpriteFrame | ( | const tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteName | ||
) | const |
Creates just the SpriteFrame data provided on the SpriteSheet for the given spriteName. If no SpriteSheet is found with the spriteSheetName, or if no sprite data is found with the spriteName an error condition will be triggered.
spriteSheetName | A name to a SpriteSheet as loaded during a call to LoadSpriteSheetFromFile() or LoadSpriteSheetFromData(). If no object is found with the sheet name, 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. |
Sprite TurtleBrains::Graphics::SpriteManager::GetSpriteFromFile | ( | const tbCore::tbString & | textureFile, |
const PixelSpace & | frameX = 0 , |
||
const PixelSpace & | frameY = 0 , |
||
const PixelSpace & | frameWidth = 0 , |
||
const PixelSpace & | frameHeight = 0 |
||
) | const |
By default this will creates a sprite that is the entire width and height of the texture loaded from the textureFile provided. If the file is unable to load from disk an error condition will be triggered. The remaining parameters are optional to setup a frame of specified location and size.
textureFile | The filepath of the image to load using theTextureManager. Will use an already loaded texture if it has been loaded previously, otherwise loads the file (or triggers an error condition if the texture file cannot be loaded. |
frameX | An optional parameter to set the horizontal location of the frame on the texture, in pixels. |
frameY | An optional parameter to set the vertical location of the frame on the texture, in pixels. |
frameWidth | An option parameter to set the width in pixels of the sprites frame. |
frameHeight | An option parameter to set the height in pixels of the sprites frame. |
TextureHandle TurtleBrains::Graphics::SpriteManager::GetSpriteSheetTextureHandle | ( | const tbCore::tbString & | spriteSheetName | ) | const |
Finds the sprite sheet previously loaded with spriteSheetName and returns the associated texture handle.
spriteSheetName | The name of the SpriteSheet to retrieve the texture handle of. |
bool TurtleBrains::Graphics::SpriteManager::LoadSpriteSheetFromFile | ( | const tbCore::tbString & | spriteSheetName, |
const tbCore::tbString & | spriteSheetFile | ||
) |
Loads a json formatted file and processes it into a DynamicStructure which is then processed with LoadSpriteSheetFromData(). If the file was not found or loaded an error condition is triggered. If the json data did not contain all required information about a sprite or animation sequence an error condition will be triggered from within LoadSpriteSheetFromData().
spriteSheetName | The name of the SpriteSheet where all the sprite and animation data will be stored. |
spriteSheetFile | The path to the json formatted file that contains the sprites and animation data to load. |
Ex. SpriteSheet:
{ "texture" : "pathToTexture", "sprites" : [ { "name" : "frame_name", "x" : 0, "y" : 0, "width" : 128, "height" : 128, "animations" : [ "idle", "jump", "death" ] }, { "name" : "frame_name", "x" : 0, "y" : 0, "width" : 128, "height" : 128, "animations" : [ { "name" : "sequence_name", "frames" : [ "sprite_frame_1", "sprite_frame_2" ... ] }, ] }, ], "animations" : [ { "name" : "sequence_name", "frames" : [ "sprite_frame_1", "sprite_frame_2" ... ] }, { "name" : "sequence_mapp", "frames" : { "startIndex" : 0, "frameCount" : 3, "width" : 32, "height" : 32, "locationX" : 0, "locationY" : 0 } }, { "name" : "sequence_mapc", "frames" : { "width" : 32, "height" : 32, "locationX" : 0, "locationY" : 0, "frames" : [ 0, 1, 5, 3 ] } } ] }