The Table Engine
animation.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include "texture.h"
9 
21 class Animation : public Texture {
22 protected:
23  int m_rows = 1;
24  int m_cols = 1;
25  float m_time = 1.0f;
26  int m_numFrames = 1;
28 
29  bool m_isPlaying = true;
30  int m_currentFrame = 0;
31  int m_startTime = 0;
32  int m_pausedTime = 0;
33 
34 public:
38  Animation();
39 
43  Animation(SDL_Texture* texture);
44 
49  int getRows();
50 
55  int getCols();
56 
61  int getNumFrames();
62 
67  void setAutoPlay(bool autoplay);
68 
72  void setRowsColsInSpriteMap(int rows, int cols);
73 
77  void setAnimationTime(float time);
78 
82  void play();
83 
87  void pause();
88 
93  void setFrame(int frame);
94 
99  int getCurrentFrame() const { return m_currentFrame; }
100 
105  bool isPlaying() const { return m_isPlaying; }
106 
110  void update() override;
111 };
Component to handle animation of game objects. Derived from Texture.
Definition: animation.h:21
void setFrame(int frame)
Sets a specific frame of animation.
Definition: animation.cpp:61
int getNumFrames()
Get the total number of frames.
Definition: animation.cpp:23
int m_rows
Number of rows in the sprite sheet.
Definition: animation.h:23
void setRowsColsInSpriteMap(int rows, int cols)
Sets the number of rows and columns in the sprite map.
Definition: animation.cpp:34
void pause()
Pauses the animation at current frame.
Definition: animation.cpp:54
int getCols()
Get the number of columns.
Definition: animation.cpp:19
int m_pausedTime
Time when animation was paused.
Definition: animation.h:32
void setAutoPlay(bool autoplay)
Sets whether the animation should start playing automatically.
Definition: animation.cpp:27
int m_cols
Number of columns in the sprite sheet.
Definition: animation.h:24
int m_msPerFrame
Milliseconds per frame.
Definition: animation.h:27
int getRows()
Get the number of rows.
Definition: animation.cpp:15
int getCurrentFrame() const
Gets the current frame number.
Definition: animation.h:99
Animation()
Default constructor.
Definition: animation.cpp:3
int m_currentFrame
Current frame of animation.
Definition: animation.h:30
bool m_isPlaying
Whether the animation is currently playing.
Definition: animation.h:29
void play()
Starts or resumes the animation.
Definition: animation.cpp:47
bool isPlaying() const
Checks if animation is currently playing.
Definition: animation.h:105
void update() override
Updates the animation state.
Definition: animation.cpp:70
float m_time
Total animation time in seconds.
Definition: animation.h:25
int m_startTime
Time when animation started/resumed.
Definition: animation.h:31
int m_numFrames
Total number of frames.
Definition: animation.h:26
void setAnimationTime(float time)
Sets the total time for the animation cycle.
Definition: animation.cpp:42
Component for handling textures in the game engine.
Definition: texture.h:20
Defines the Texture component for managing textures within the Game Engine, encapsulating SDL texture...