GameKit  0.0.1a
C++ gamedev tools
SpriteAnimation.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: SpriteAnimation.hpp
5  *
6  * Description:
7  *
8  * Created: 25/01/2018 04:07:17
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_SPRITEANIMATION_HPP_
15 #define GK_SPRITEANIMATION_HPP_
16 
17 #include <vector>
18 
19 #include "gk/core/Timer.hpp"
20 
21 namespace gk {
22 
24  public:
25  SpriteAnimation(u16 delay, bool isRepeated = true)
26  : m_delay(delay), m_isRepeated(isRepeated) {}
27 
28  void reset(u16 frameID = 0);
29 
30  void start();
31  void stop();
32 
33  void play();
34 
35  void addFrame(u16 frameID) { m_frames.emplace_back(frameID); }
36  u16 getFrame(u16 frameID) const;
37  u16 currentFrame() const;
38  u16 displayedFramesAmount() const;
39 
40  bool isPlaying() const { return m_timer.isStarted() && !m_isPaused; }
41  bool isFinished() const { return displayedFramesAmount() >= m_frames.size(); }
42 
43  u32 size() const { return m_frames.size(); }
44 
45  u16 delay() const { return m_delay; }
46 
47  void setRepeated(bool isRepeated) { m_isRepeated = isRepeated; }
48 
49  private:
50  std::vector<u16> m_frames;
51 
53 
54  u16 m_delay = 0;
55 
56  bool m_isPaused = false;
57  bool m_isRepeated = true;
58 };
59 
60 } // namespace gk
61 
62 #endif // GK_SPRITEANIMATION_HPP_
SpriteAnimation(u16 delay, bool isRepeated=true)
unsigned short u16
Definition: IntTypes.hpp:22
std::vector< u16 > m_frames
void reset(u16 frameID=0)
unsigned int u32
Definition: IntTypes.hpp:23
u16 getFrame(u16 frameID) const
void addFrame(u16 frameID)
bool isStarted() const
Check if the timer is started.
Definition: Timer.hpp:75
u16 displayedFramesAmount() const
Very basic timer.
Definition: Timer.hpp:25
void setRepeated(bool isRepeated)