Animates a sprite by adding playback state.
More...
#include <sprite.h>
|
| Sprite (SpriteDef *sprite) |
| Constructor.
|
|
| ~Sprite () |
|
bool | reset () |
| Resets the sprite.
|
|
bool | play (const std::string &action) |
| Plays an action using the current direction.
|
|
bool | update (int time) |
| Inform the animation of the passed time so that it can output the correct animation frame.
|
|
bool | draw (Graphics *graphics, int posX, int posY) const |
| Draw the current animation frame at the coordinates given in screen pixels.
|
|
int | getWidth () const |
| Gets the width in pixels of the image.
|
|
int | getHeight () const |
| Gets the height in pixels of the image.
|
|
int | getOffsetX () const |
| Gets the horizontal offset that the sprite will be drawn at.
|
|
int | getOffsetY () const |
| Gets the vertical offset that the sprite will be drawn at.
|
|
const Image * | getImage () const |
| Returns a reference to the current image being drawn.
|
|
bool | setDirection (SpriteDirection direction) |
| Sets the direction.
|
|
void | setAlpha (float alpha) |
| Sets the alpha value of the sprite.
|
|
float | getAlpha () const |
| Returns the current alpha opacity of the sprite.
|
|
int | getDuration () const |
| Returns the duration of the current sprite animation in milliseconds.
|
|
|
static Sprite * | load (const std::string &filename, int variant=0) |
| An helper function, which will request the sprite to animate from the resource manager.
|
|
Animates a sprite by adding playback state.
Definition at line 36 of file sprite.h.
◆ Sprite()
Constructor.
- Parameters
-
sprite | the sprite to animate |
Definition at line 33 of file sprite.cpp.
◆ ~Sprite()
◆ draw()
bool Sprite::draw |
( |
Graphics * |
graphics, |
|
|
int |
posX, |
|
|
int |
posY |
|
) |
| const |
Draw the current animation frame at the coordinates given in screen pixels.
Definition at line 133 of file sprite.cpp.
◆ getAlpha()
float Sprite::getAlpha |
( |
| ) |
const |
|
inline |
Returns the current alpha opacity of the sprite.
Definition at line 124 of file sprite.h.
◆ getDuration()
int Sprite::getDuration |
( |
| ) |
const |
Returns the duration of the current sprite animation in milliseconds.
Definition at line 172 of file sprite.cpp.
◆ getHeight()
int Sprite::getHeight |
( |
| ) |
const |
Gets the height in pixels of the image.
Definition at line 186 of file sprite.cpp.
◆ getImage()
const Image * Sprite::getImage |
( |
| ) |
const |
Returns a reference to the current image being drawn.
Definition at line 203 of file sprite.cpp.
◆ getOffsetX()
int Sprite::getOffsetX |
( |
| ) |
const |
Gets the horizontal offset that the sprite will be drawn at.
Definition at line 193 of file sprite.cpp.
◆ getOffsetY()
int Sprite::getOffsetY |
( |
| ) |
const |
Gets the vertical offset that the sprite will be drawn at.
Definition at line 198 of file sprite.cpp.
◆ getWidth()
int Sprite::getWidth |
( |
| ) |
const |
Gets the width in pixels of the image.
Definition at line 179 of file sprite.cpp.
◆ load()
Sprite * Sprite::load |
( |
const std::string & |
filename, |
|
|
int |
variant = 0 |
|
) |
| |
|
static |
An helper function, which will request the sprite to animate from the resource manager.
- Parameters
-
filename | the file of the sprite to animate |
variant | the sprite variant |
Definition at line 42 of file sprite.cpp.
◆ play()
bool Sprite::play |
( |
const std::string & |
action | ) |
|
Plays an action using the current direction.
- Returns
- true if the sprite changed, false otherwise
Definition at line 67 of file sprite.cpp.
◆ reset()
Resets the sprite.
- Returns
- true if the sprite changed, false otherwise
Definition at line 53 of file sprite.cpp.
◆ setAlpha()
void Sprite::setAlpha |
( |
float |
alpha | ) |
|
|
inline |
Sets the alpha value of the sprite.
Definition at line 119 of file sprite.h.
◆ setDirection()
Sets the direction.
- Returns
- true if the sprite changed, false otherwise
Definition at line 149 of file sprite.cpp.
◆ update()
bool Sprite::update |
( |
int |
time | ) |
|
Inform the animation of the passed time so that it can output the correct animation frame.
- Returns
- true if the sprite changed, false otherwise
Definition at line 87 of file sprite.cpp.
◆ updateCurrentAnimation()
bool Sprite::updateCurrentAnimation |
( |
int |
dt | ) |
|
|
private |
◆ mAction
Action* Sprite::mAction = nullptr |
|
private |
The currently active action.
Definition at line 142 of file sprite.h.
◆ mAlpha
float Sprite::mAlpha = 1.0f |
|
private |
The alpha opacity used to draw.
Definition at line 134 of file sprite.h.
◆ mAnimation
The currently active animation.
Definition at line 143 of file sprite.h.
◆ mDirection
The sprite direction.
Definition at line 136 of file sprite.h.
◆ mFrame
Frame* Sprite::mFrame = nullptr |
|
private |
The currently active frame.
Definition at line 144 of file sprite.h.
◆ mFrameIndex
int Sprite::mFrameIndex = 0 |
|
private |
The index of the current frame.
Definition at line 138 of file sprite.h.
◆ mFrameTime
int Sprite::mFrameTime = 0 |
|
private |
The time since start of frame.
Definition at line 139 of file sprite.h.
◆ mSprite
The sprite definition.
Definition at line 141 of file sprite.h.
The documentation for this class was generated from the following files: