The Table Engine
Animation Class Reference

Component to handle animation of game objects. Derived from Texture. More...

#include <animation.h>

+ Inheritance diagram for Animation:
+ Collaboration diagram for Animation:

Public Member Functions

 Animation ()
 Default constructor. More...
 
 Animation (SDL_Texture *texture)
 Constructs an Animation with an associated SDL_Texture. More...
 
int getRows ()
 Get the number of rows. More...
 
int getCols ()
 Get the number of columns. More...
 
int getNumFrames ()
 Get the total number of frames. More...
 
void setAutoPlay (bool autoplay)
 Sets whether the animation should start playing automatically. More...
 
void setRowsColsInSpriteMap (int rows, int cols)
 Sets the number of rows and columns in the sprite map. More...
 
void setAnimationTime (float time)
 Sets the total time for the animation cycle. More...
 
void play ()
 Starts or resumes the animation. More...
 
void pause ()
 Pauses the animation at current frame. More...
 
void setFrame (int frame)
 Sets a specific frame of animation. More...
 
int getCurrentFrame () const
 Gets the current frame number. More...
 
bool isPlaying () const
 Checks if animation is currently playing. More...
 
void update () override
 Updates the animation state. 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...
 
virtual void setTexture (SDL_Texture *texture)
 Sets the SDL_Texture object. More...
 
virtual void setSizeInSpriteMap (int w, int h)
 Sets the size of the sprite in the sprite map. More...
 
virtual void setPositionInSpriteMap (int x, int y)
 Sets the position of the sprite in the sprite map. More...
 
virtual void setFlipHorizontal (bool flip)
 Sets horizontal flip status. More...
 
virtual void setFlipVertical (bool flip)
 Sets vertical flip status. More...
 
virtual void setAngle (float angle)
 Sets the rotation angle of the texture. More...
 
virtual void render () override
 Renders the texture to the screen based on current properties. 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

int m_rows = 1
 Number of rows in the sprite sheet. More...
 
int m_cols = 1
 Number of columns in the sprite sheet. More...
 
float m_time = 1.0f
 Total animation time in seconds. More...
 
int m_numFrames = 1
 Total number of frames. More...
 
int m_msPerFrame
 Milliseconds per frame. More...
 
bool m_isPlaying = true
 Whether the animation is currently playing. More...
 
int m_currentFrame = 0
 Current frame of animation. More...
 
int m_startTime = 0
 Time when animation started/resumed. More...
 
int m_pausedTime = 0
 Time when animation was paused. 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

Component to handle animation of game objects. Derived from Texture.

Animation extends the Texture class to provide functionalities for sprite animations. It allows for setting the number of rows and columns in the sprite sheet, the total animation time, and the current frame of animation. It also provides methods to start, pause, and resume the animation, as well as to set a specific frame of animation. The update method is used to advance the animation frame based on the elapsed time. The render method is inherited from Texture and is used to render the current frame.

Definition at line 21 of file animation.h.

Constructor & Destructor Documentation

◆ Animation() [1/2]

Animation::Animation ( )

Default constructor.

Definition at line 3 of file animation.cpp.

◆ Animation() [2/2]

Animation::Animation ( SDL_Texture *  texture)

Constructs an Animation with an associated SDL_Texture.

Definition at line 9 of file animation.cpp.

Member Function Documentation

◆ getCols()

int Animation::getCols ( )

Get the number of columns.

Returns
int

Definition at line 19 of file animation.cpp.

◆ getCurrentFrame()

int Animation::getCurrentFrame ( ) const

Gets the current frame number.

Returns
Current frame number (0-based)

Definition at line 99 of file animation.h.

◆ getNumFrames()

int Animation::getNumFrames ( )

Get the total number of frames.

Returns
int

Definition at line 23 of file animation.cpp.

◆ getRows()

int Animation::getRows ( )

Get the number of rows.

Returns
int

Definition at line 15 of file animation.cpp.

◆ isPlaying()

bool Animation::isPlaying ( ) const

Checks if animation is currently playing.

Returns
True if animation is playing, false if paused

Definition at line 105 of file animation.h.

◆ pause()

void Animation::pause ( )

Pauses the animation at current frame.

Definition at line 54 of file animation.cpp.

◆ play()

void Animation::play ( )

Starts or resumes the animation.

Definition at line 47 of file animation.cpp.

◆ setAnimationTime()

void Animation::setAnimationTime ( float  time)

Sets the total time for the animation cycle.

Definition at line 42 of file animation.cpp.

◆ setAutoPlay()

void Animation::setAutoPlay ( bool  autoplay)

Sets whether the animation should start playing automatically.

Parameters
autoplayTrue to start playing immediately, false to start paused

Definition at line 27 of file animation.cpp.

◆ setFrame()

void Animation::setFrame ( int  frame)

Sets a specific frame of animation.

Parameters
frameThe frame number to display (0-based)

Definition at line 61 of file animation.cpp.

◆ setRowsColsInSpriteMap()

void Animation::setRowsColsInSpriteMap ( int  rows,
int  cols 
)

Sets the number of rows and columns in the sprite map.

Definition at line 34 of file animation.cpp.

◆ update()

void Animation::update ( )
overridevirtual

Updates the animation state.

Reimplemented from Texture.

Definition at line 70 of file animation.cpp.

Member Data Documentation

◆ m_cols

int Animation::m_cols = 1
protected

Number of columns in the sprite sheet.

Definition at line 24 of file animation.h.

◆ m_currentFrame

int Animation::m_currentFrame = 0
protected

Current frame of animation.

Definition at line 30 of file animation.h.

◆ m_isPlaying

bool Animation::m_isPlaying = true
protected

Whether the animation is currently playing.

Definition at line 29 of file animation.h.

◆ m_msPerFrame

int Animation::m_msPerFrame
protected

Milliseconds per frame.

Definition at line 27 of file animation.h.

◆ m_numFrames

int Animation::m_numFrames = 1
protected

Total number of frames.

Definition at line 26 of file animation.h.

◆ m_pausedTime

int Animation::m_pausedTime = 0
protected

Time when animation was paused.

Definition at line 32 of file animation.h.

◆ m_rows

int Animation::m_rows = 1
protected

Number of rows in the sprite sheet.

Definition at line 23 of file animation.h.

◆ m_startTime

int Animation::m_startTime = 0
protected

Time when animation started/resumed.

Definition at line 31 of file animation.h.

◆ m_time

float Animation::m_time = 1.0f
protected

Total animation time in seconds.

Definition at line 25 of file animation.h.


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