The Table Engine
AnimationsManager Class Reference

Manages a collection of animations for a game entity, with functionality to play, pause, and switch between animations. More...

#include <animationsmanager.h>

+ Inheritance diagram for AnimationsManager:
+ Collaboration diagram for AnimationsManager:

Public Member Functions

 AnimationsManager ()
 
 ~AnimationsManager ()
 
int addAnimation (Animation *animation)
 
int createAnimation (SDL_Texture *texture, int rows, int cols, float time)
 
void setCurrentAnimation (size_t index)
 
size_t getCurrentAnimation () const
 
AnimationgetCurrentAnimationObject ()
 
void play ()
 
void pause ()
 
void setFrame (int frame)
 
int getCurrentFrame () const
 
bool isPlaying () const
 
void update () override
 
void render () override
 
void setTexture (SDL_Texture *texture) override
 Sets the SDL_Texture object. More...
 
void setSizeInSpriteMap (int w, int h) override
 Sets the size of the sprite in the sprite map. More...
 
void setPositionInSpriteMap (int x, int y) override
 Sets the position of the sprite in the sprite map. More...
 
void setFlipHorizontal (bool flip) override
 Sets horizontal flip status. More...
 
void setFlipVertical (bool flip) override
 Sets vertical flip status. More...
 
void setAngle (float angle) override
 Sets the rotation angle of the texture. More...
 
- Public Member Functions inherited from Texture
 Texture ()
 Default constructor for the Texture class, initializes an empty texture. More...
 
 Texture (SDL_Texture *texture)
 Constructor with texture initialization. More...
 
SDL_Texture * getTexture ()
 Retrieves the SDL_Texture object. More...
 
void setColorMod (const SDL_Color &color)
 Sets the color modulation for the texture. More...
 
- Public Member Functions inherited from Component
 Component ()
 Default constructor for the Component. More...
 
 Component (std::string name)
 Constructs a Component with a specified name. More...
 
virtual ~Component ()
 Virtual destructor for safe polymorphic use. More...
 
std::string getName ()
 Retrieves the name of the component. More...
 
GameObjectgetOwner ()
 Retrieves the GameObject that owns this component. More...
 
void setName (std::string name)
 Sets the name of the component. More...
 
void setOwner (GameObject *owner)
 Sets the GameObject owner of this component. More...
 
virtual void input ()
 Virtual method for handling input, intended to be overridden by derived components. More...
 

Protected Attributes

std::vector< Animation * > m_animations
 Stores pointers to Animation objects. More...
 
size_t m_currentAnimation = 0
 Index of the currently active animation. More...
 
bool m_isPlaying = true
 Flag to check if the animation is currently playing. More...
 
- Protected Attributes inherited from Texture
SDL_Texture * m_texture
 Pointer to the SDL_Texture object. More...
 
SDL_Renderer * m_renderer
 Pointer to the SDL_Renderer associated with this texture. More...
 
SDL_Rect * m_spriteBox
 Destination rectangle on the screen for rendering the texture. More...
 
SDL_Rect * m_spriteClip
 Source rectangle in the sprite sheet for slicing the texture. More...
 
bool m_flipHorizontal = false
 Flag for horizontal flipping of the texture. More...
 
bool m_flipVertical = false
 Flag for vertical flipping of the texture. More...
 
float m_angle = 0.0f
 Rotation angle of the texture in degrees. More...
 
- Protected Attributes inherited from Component
std::string m_name
 Name of the component, useful for identification or debugging. More...
 
GameObjectm_owner
 Pointer to the GameObject that owns this component. More...
 

Detailed Description

Manages a collection of animations for a game entity, with functionality to play, pause, and switch between animations.

AnimationsManager extends Texture, allowing it to directly control the rendering of animations based on the Texture properties.

Definition at line 16 of file animationsmanager.h.

Constructor & Destructor Documentation

◆ AnimationsManager()

AnimationsManager::AnimationsManager ( )

Definition at line 4 of file animationsmanager.cpp.

◆ ~AnimationsManager()

AnimationsManager::~AnimationsManager ( )

Definition at line 8 of file animationsmanager.cpp.

Member Function Documentation

◆ addAnimation()

int AnimationsManager::addAnimation ( Animation animation)

Adds a new Animation object to the manager.

Parameters
animationPointer to the Animation to add.
Returns
The index of the added animation within the manager.

Definition at line 58 of file animationsmanager.cpp.

◆ createAnimation()

int AnimationsManager::createAnimation ( SDL_Texture *  texture,
int  rows,
int  cols,
float  time 
)

Creates a new animation directly from texture details and adds it to the manager.

Parameters
texturePointer to the SDL_Texture resource.
rowsNumber of rows in the sprite sheet.
colsNumber of columns in the sprite sheet.
timeDuration of each animation frame.
Returns
The index of the created animation.

Definition at line 65 of file animationsmanager.cpp.

◆ getCurrentAnimation()

size_t AnimationsManager::getCurrentAnimation ( ) const

Retrieves the index of the currently active animation.

Returns
Index of the current animation.

Definition at line 76 of file animationsmanager.cpp.

◆ getCurrentAnimationObject()

Animation * AnimationsManager::getCurrentAnimationObject ( )

Gets the Animation object of the currently active animation.

Returns
Pointer to the current Animation object.

Definition at line 86 of file animationsmanager.cpp.

◆ getCurrentFrame()

int AnimationsManager::getCurrentFrame ( ) const

Gets the current frame number of the animation.

Returns
Current frame number.

Definition at line 113 of file animationsmanager.cpp.

◆ isPlaying()

bool AnimationsManager::isPlaying ( ) const

Checks if the animation is currently playing.

Returns
True if the animation is playing, false otherwise.

Definition at line 72 of file animationsmanager.cpp.

◆ pause()

void AnimationsManager::pause ( )

Pauses the current animation.

Definition at line 100 of file animationsmanager.cpp.

◆ play()

void AnimationsManager::play ( )

Starts or resumes playing the current animation.

Definition at line 93 of file animationsmanager.cpp.

◆ render()

void AnimationsManager::render ( )
overridevirtual

Renders the current frame of the animation. Should be called per frame.

Reimplemented from Texture.

Definition at line 126 of file animationsmanager.cpp.

◆ setAngle()

void AnimationsManager::setAngle ( float  angle)
overridevirtual

Sets the rotation angle of the texture.

Parameters
angleRotation angle in degrees.

Reimplemented from Texture.

Definition at line 51 of file animationsmanager.cpp.

◆ setCurrentAnimation()

void AnimationsManager::setCurrentAnimation ( size_t  index)

Sets the currently active animation.

Parameters
indexIndex of the animation to make active.

Definition at line 80 of file animationsmanager.cpp.

◆ setFlipHorizontal()

void AnimationsManager::setFlipHorizontal ( bool  flip)
overridevirtual

Sets horizontal flip status.

Parameters
flipTrue to flip the texture horizontally, false otherwise.

Reimplemented from Texture.

Definition at line 37 of file animationsmanager.cpp.

◆ setFlipVertical()

void AnimationsManager::setFlipVertical ( bool  flip)
overridevirtual

Sets vertical flip status.

Parameters
flipTrue to flip the texture vertically, false otherwise.

Reimplemented from Texture.

Definition at line 44 of file animationsmanager.cpp.

◆ setFrame()

void AnimationsManager::setFrame ( int  frame)

Sets the frame number of the current animation.

Parameters
frameFrame number to set.

Definition at line 107 of file animationsmanager.cpp.

◆ setPositionInSpriteMap()

void AnimationsManager::setPositionInSpriteMap ( int  x,
int  y 
)
overridevirtual

Sets the position of the sprite in the sprite map.

Parameters
xHorizontal position of the sprite in the sprite sheet.
yVertical position of the sprite in the sprite sheet.

Reimplemented from Texture.

Definition at line 30 of file animationsmanager.cpp.

◆ setSizeInSpriteMap()

void AnimationsManager::setSizeInSpriteMap ( int  w,
int  h 
)
overridevirtual

Sets the size of the sprite in the sprite map.

Parameters
wWidth of the sprite in the sprite sheet.
hHeight of the sprite in the sprite sheet.

Reimplemented from Texture.

Definition at line 23 of file animationsmanager.cpp.

◆ setTexture()

void AnimationsManager::setTexture ( SDL_Texture *  texture)
overridevirtual

Sets the SDL_Texture object.

Parameters
texturePointer to the new SDL_Texture to be managed.

Reimplemented from Texture.

Definition at line 15 of file animationsmanager.cpp.

◆ update()

void AnimationsManager::update ( )
overridevirtual

Updates the current animation state. Should be called per frame.

Reimplemented from Texture.

Definition at line 120 of file animationsmanager.cpp.

Member Data Documentation

◆ m_animations

std::vector<Animation*> AnimationsManager::m_animations
protected

Stores pointers to Animation objects.

Definition at line 18 of file animationsmanager.h.

◆ m_currentAnimation

size_t AnimationsManager::m_currentAnimation = 0
protected

Index of the currently active animation.

Definition at line 19 of file animationsmanager.h.

◆ m_isPlaying

bool AnimationsManager::m_isPlaying = true
protected

Flag to check if the animation is currently playing.

Definition at line 20 of file animationsmanager.h.


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