The Table Engine
|
Component to handle animation of game objects. Derived from Texture. More...
#include <animation.h>
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... | |
![]() | |
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... | |
![]() | |
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... | |
GameObject * | getOwner () |
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... | |
![]() | |
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... | |
![]() | |
std::string | m_name |
Name of the component, useful for identification or debugging. More... | |
GameObject * | m_owner |
Pointer to the GameObject that owns this component. More... | |
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.
Animation::Animation | ( | ) |
Default constructor.
Definition at line 3 of file animation.cpp.
Animation::Animation | ( | SDL_Texture * | texture | ) |
Constructs an Animation with an associated SDL_Texture.
Definition at line 9 of file animation.cpp.
int Animation::getCols | ( | ) |
int Animation::getCurrentFrame | ( | ) | const |
Gets the current frame number.
Definition at line 99 of file animation.h.
int Animation::getNumFrames | ( | ) |
int Animation::getRows | ( | ) |
bool Animation::isPlaying | ( | ) | const |
Checks if animation is currently playing.
Definition at line 105 of file animation.h.
void Animation::pause | ( | ) |
Pauses the animation at current frame.
Definition at line 54 of file animation.cpp.
void Animation::play | ( | ) |
Starts or resumes the animation.
Definition at line 47 of file animation.cpp.
void Animation::setAnimationTime | ( | float | time | ) |
Sets the total time for the animation cycle.
Definition at line 42 of file animation.cpp.
void Animation::setAutoPlay | ( | bool | autoplay | ) |
Sets whether the animation should start playing automatically.
autoplay | True to start playing immediately, false to start paused |
Definition at line 27 of file animation.cpp.
void Animation::setFrame | ( | int | frame | ) |
Sets a specific frame of animation.
frame | The frame number to display (0-based) |
Definition at line 61 of file animation.cpp.
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.
|
overridevirtual |
Updates the animation state.
Reimplemented from Texture.
Definition at line 70 of file animation.cpp.
|
protected |
Number of columns in the sprite sheet.
Definition at line 24 of file animation.h.
|
protected |
Current frame of animation.
Definition at line 30 of file animation.h.
|
protected |
Whether the animation is currently playing.
Definition at line 29 of file animation.h.
|
protected |
Milliseconds per frame.
Definition at line 27 of file animation.h.
|
protected |
Total number of frames.
Definition at line 26 of file animation.h.
|
protected |
Time when animation was paused.
Definition at line 32 of file animation.h.
|
protected |
Number of rows in the sprite sheet.
Definition at line 23 of file animation.h.
|
protected |
Time when animation started/resumed.
Definition at line 31 of file animation.h.
|
protected |
Total animation time in seconds.
Definition at line 25 of file animation.h.