Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes

Sprite Class Reference

Sprite Resource. More...

#include <Sprite.h>

List of all members.

Classes

struct  spriteFrame
 Contains all information necessary for animation frames of a Sprite. More...

Public Member Functions

 Sprite (const std::string &filePath)
 Sprite (const Sprite &sprite)
 ~Sprite ()
Spriteoperator= (const Sprite &rhs)
void play (const std::string &action)
void pause (bool pause)
void update (int x, int y)
void setAlpha (int alpha)
ImagegetCurrentFrameImage ()
const int getWidth () const
const int getHeight () const
const int getOriginX (int x) const
const int getOriginY (int y) const
void debug ()

Private Types

typedef std::vector
< spriteFrame * > 
FrameList
typedef std::map< string,
FrameList
ActionList
typedef std::map< string, Image * > SheetContainer

Private Member Functions

bool parseXml (const std::string &filePath)
bool parseImageSheets (TiXmlElement *root)
bool parseActions (TiXmlElement *root)
void parseFrames (TiXmlNode *node, const std::string &action)
void addDefaultFrame (FrameList &frmList, Uint frmDelay=25)
void addDefaultAction ()

Private Attributes

TimermTimer
TiXmlDocument * mDocXml
SheetContainer mSpriteSheets
ActionList mActions
FrameListmPlayingAction
std::string mSpriteName
std::string mErrorMessage
std::string mCurrentAction
Uint mCurrentFrame
Uint mLastFrameTick
int mAlpha
bool mPaused

Detailed Description

Sprite Resource.

The Sprite Class is a self-contained group of Image Resource's that displays Image's at a specified screen coordinate in sequence to display an animation.


Member Typedef Documentation

typedef std::map<string, FrameList> Sprite::ActionList [private]
typedef std::vector<spriteFrame*> Sprite::FrameList [private]
typedef std::map<string, Image*> Sprite::SheetContainer [private]

Constructor & Destructor Documentation

Sprite::Sprite ( const std::string &  filePath  ) 
Sprite::Sprite ( const Sprite sprite  ) 

Copy Constructor

Sprite::~Sprite (  ) 

Clean up memory allocated for animation frames and such.


Member Function Documentation

void Sprite::addDefaultAction (  )  [private]

Adds a 'default' action to the action list.

Note:
This function will not override a 'default' action if one has has already been specified.
void Sprite::addDefaultFrame ( FrameList frmList,
Uint  frmDelay = 25 
) [private]

Adds a default frame image to a frame list.

Parameters:
frmList A reference to a FrameList.
frmDelay Frame delay, in miliseconds. Default: 25.
Note:
This function does not check for validity of parameters passed in.
void Sprite::debug (  ) 

Spits out a bit of debug info on the Sprite.

Image * Sprite::getCurrentFrameImage (  ) 

Gets a pointer to the current frame image.

Warning:
Returned pointer is owned by the Sprite. Do not free it.
const int Sprite::getHeight (  )  const [inline]
const int Sprite::getOriginX ( int  x  )  const [inline]
const int Sprite::getOriginY ( int  y  )  const [inline]
const int Sprite::getWidth (  )  const [inline]
Sprite & Sprite::operator= ( const Sprite rhs  ) 

Assignment Operator

bool Sprite::parseActions ( TiXmlElement *  root  )  [private]

Parses through and interpretes <action> tags within a Sprite XML Definition File.

Todo:
Make use of mErrorMessage.
void Sprite::parseFrames ( TiXmlNode *  node,
const std::string &  action 
) [private]
bool Sprite::parseImageSheets ( TiXmlElement *  root  )  [private]

Parses through and interpretes <imagesheet> tags within a Sprite XML Definition File.

Todo:
Make use of mErrorMessage.
bool Sprite::parseXml ( const std::string &  filePath  )  [private]
void Sprite::pause ( bool  pause  ) 

Pauses animation for this Sprite.

void Sprite::play ( const std::string &  action  ) 
void Sprite::setAlpha ( int  alpha  )  [inline]
void Sprite::update ( int  x,
int  y 
)

Instructs the Sprite to update itself.

Updates the internal state of the Sprite, pushing forward animation frames as necessary.

Parameters:
x X-Screen Coordinate to render the Sprite.
y X-Screen Coordinate to render the Sprite.

Member Data Documentation

A list of Actions and their associated Frames.

int Sprite::mAlpha [private]

Alpha value to draw the sprite.

std::string Sprite::mCurrentAction [private]

The current Action being performed.

The current frame index in the current Action's frame list.

TiXmlDocument* Sprite::mDocXml [private]

XML Document Object.

std::string Sprite::mErrorMessage [private]

The last error that occured with this Sprite.

The last tick in which the frame was updated.

bool Sprite::mPaused [private]

Indicate whether or not the animation for this Sprite is paused.

A pointer to the current action being played.

std::string Sprite::mSpriteName [private]

Name of this Sprite.

Collection of sprite sheets.

Timer* Sprite::mTimer [private]

Internal time keeper.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines