#include <sprite.h>
Public Member Functions | |
Sprite () | |
Default constructor. | |
void | toggleLoop (bool b) |
Flag whether or not this sprite should loop the animations. | |
bool | loop () |
See if looping is enabled. | |
bool | done () |
See if this sprite has finished playing. | |
void | setAnimation (const ustring &anim) |
Set the animation to play. | |
void | animate (int x, int y, SDL_Surface *dest=SDL_GetVideoSurface()) |
Animate the sprite. | |
void | renderFrame (const Point &p, int frame=0) |
Render a single frame of current animation. | |
void | addAnimation (const Animation &anim) |
Add an entire animation to the sprite. | |
ustring | getCurrentAnimationId () const |
Get the ID of the current animation. | |
Animation * | getAnimation (const ustring &id) |
Get an animation sequence. | |
AnimationMap | getAnimations () const |
Get the full map of animations. | |
Frame * | getCurrentFrame () |
Get the current frame. | |
int | numAnimations () const |
Get the amount of animations in this sprite. | |
void | addFrame (const ustring &id, int time, SDL_Surface *frame) |
Add a frame to an animation sequence. | |
void | reset () |
Reset the sprite. | |
Private Attributes | |
ustring | m_CurAnim |
int | m_CurFrame |
int | m_LastFrame |
AnimationMap | m_Animations |
Internal map of animations. |
The Sprite class stores all of the image data needed to function. It also keeps track of the current frame of animation, as well as management of many animations. In addition, it provides the utility to create animations from a series of GIF files. Besides just storing data, the Sprite class is also in charge of playing the actual animations, including correctly timing each frame.
void Sprite::toggleLoop | ( | bool | b | ) |
Flag whether or not this sprite should loop the animations.
b | true to enable, false to disable |
bool Sprite::loop | ( | ) |
See if looping is enabled.
bool Sprite::done | ( | ) |
See if this sprite has finished playing.
void Sprite::setAnimation | ( | const ustring & | anim | ) |
Set the animation to play.
anim | The ID of the animation |
void Sprite::animate | ( | int | x, | |
int | y, | |||
SDL_Surface * | dest = SDL_GetVideoSurface() | |||
) |
Animate the sprite.
x | The x-coordinate where to draw the sprite | |
y | The y-coordinate where to draw the sprite | |
dest | The destination surface |
void Sprite::renderFrame | ( | const Point & | p, | |
int | frame = 0 | |||
) |
Render a single frame of current animation.
p | The point where to draw | |
frame | The frame to draw |
void Sprite::addAnimation | ( | const Animation & | anim | ) | [inline] |
Add an entire animation to the sprite.
anim | The animation to add |
ustring Sprite::getCurrentAnimationId | ( | ) | const [inline] |
Get the ID of the current animation.
Animation * Sprite::getAnimation | ( | const ustring & | id | ) |
Get an animation sequence.
id | The ID of the animation |
AnimationMap Sprite::getAnimations | ( | ) | const [inline] |
Get the full map of animations.
Frame * Sprite::getCurrentFrame | ( | ) |
Get the current frame.
int Sprite::numAnimations | ( | ) | const [inline] |
Get the amount of animations in this sprite.
void Sprite::addFrame | ( | const ustring & | id, | |
int | time, | |||
SDL_Surface * | frame | |||
) |
Add a frame to an animation sequence.
id | The ID of the target animation | |
time | The time duration of the frame | |
frame | The frame image |