Mana
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Sprite Class Reference

Animates a sprite by adding playback state. More...

#include <sprite.h>

Public Member Functions

 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 ImagegetImage () 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 Public Member Functions

static Spriteload (const std::string &filename, int variant=0)
 An helper function, which will request the sprite to animate from the resource manager.
 

Private Member Functions

bool updateCurrentAnimation (int dt)
 

Private Attributes

float mAlpha = 1.0f
 The alpha opacity used to draw.
 
SpriteDirection mDirection = DIRECTION_DOWN
 The sprite direction.
 
int mFrameIndex = 0
 The index of the current frame.
 
int mFrameTime = 0
 The time since start of frame.
 
ResourceRef< SpriteDefmSprite
 The sprite definition.
 
ActionmAction = nullptr
 The currently active action.
 
AnimationmAnimation = nullptr
 The currently active animation.
 
FramemFrame = nullptr
 The currently active frame.
 

Detailed Description

Animates a sprite by adding playback state.

Definition at line 36 of file sprite.h.

Constructor & Destructor Documentation

◆ Sprite()

Sprite::Sprite ( SpriteDef sprite)

Constructor.

Parameters
spritethe sprite to animate

Definition at line 33 of file sprite.cpp.

◆ ~Sprite()

Sprite::~Sprite ( )
default

Member Function Documentation

◆ 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
filenamethe file of the sprite to animate
variantthe 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()

bool Sprite::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()

bool Sprite::setDirection ( SpriteDirection  direction)

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

Definition at line 105 of file sprite.cpp.

Member Data Documentation

◆ 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

Animation* Sprite::mAnimation = nullptr
private

The currently active animation.

Definition at line 143 of file sprite.h.

◆ mDirection

SpriteDirection Sprite::mDirection = DIRECTION_DOWN
private

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

ResourceRef<SpriteDef> Sprite::mSprite
private

The sprite definition.

Definition at line 141 of file sprite.h.


The documentation for this class was generated from the following files: