Practical Tools for Simple Design
Loading...
Searching...
No Matches
Animation.hpp
1#ifndef UTIL_ANIMATION_HPP
2#define UTIL_ANIMATION_HPP
3
4#include "pch.hpp"
5
6#include <exception>
7
8#include "Core/Drawable.hpp"
9
10#include "Util/Image.hpp"
11
12namespace Util {
17class Animation : public Core::Drawable {
18public:
22 enum class State {
23 PLAY,
24 PAUSE,
25 COOLDOWN,
26 ENDED
27 };
28
38 Animation(const std::vector<std::string> &paths, bool play,
39 std::size_t interval, bool looping = true,
40 std::size_t cooldown = 100, bool useAA = true);
41
46 int GetInterval() const { return m_Interval; }
47
52 bool GetLooping() const { return m_Looping; }
53
58 int GetCooldown() const { return m_Cooldown; }
59
64 std::size_t GetCurrentFrameIndex() const { return m_Index; }
65
70 std::size_t GetFrameCount() const { return m_Frames.size(); }
71
76 State GetState() const { return m_State; }
77
82 glm::vec2 GetSize() const override { return m_Frames[m_Index]->GetSize(); }
83
88 void SetInterval(int interval) { m_Interval = interval; }
89
94 void SetLooping(bool looping) { m_Looping = looping; }
95
100 void SetCooldown(int cooldown) { m_Cooldown = cooldown; }
101
114 void UseAntiAliasing(bool useAA);
115
120 void SetCurrentFrame(std::size_t index);
121
127 void Draw(const Core::Matrices &data) override;
128
135 void Play();
136
141 void Pause();
142
143private:
147 void Update();
148
149private:
150 std::vector<std::shared_ptr<Util::Image>> m_Frames;
151 State m_State;
152 double m_Interval;
153 bool m_Looping;
154 std::size_t m_Cooldown;
155 bool m_IsChangeFrame = false;
156
157 unsigned long m_CooldownEndTime = 0;
158 double m_TimeBetweenFrameUpdate = 0;
159
160 std::size_t m_Index = 0;
161};
162} // namespace Util
163
164#endif
Definition: Drawable.hpp:14
Class representing an animation with frames.
Definition: Animation.hpp:17
void Pause()
Pause the animation. If the animation has already been paused, this method won't do anything.
int GetCooldown() const
Get the cooldown time.
Definition: Animation.hpp:58
State
Enum representing the state of the animation.
Definition: Animation.hpp:22
void UseAntiAliasing(bool useAA)
Sets whether anti-aliasing (AA) should be enabled or disabled.
void Play()
Start playing the animation. If the animation is already playing, this method won't do anything....
void Draw(const Core::Matrices &data) override
Draw the current frame.
int GetInterval() const
Get the interval between frames.
Definition: Animation.hpp:46
void SetLooping(bool looping)
Set whether the animation loops.
Definition: Animation.hpp:94
void SetCooldown(int cooldown)
Set the cooldown time.
Definition: Animation.hpp:100
void SetInterval(int interval)
Set the interval between frames.
Definition: Animation.hpp:88
bool GetLooping() const
Check if the animation loops.
Definition: Animation.hpp:52
std::size_t GetCurrentFrameIndex() const
Get the index of the current frame.
Definition: Animation.hpp:64
Animation(const std::vector< std::string > &paths, bool play, std::size_t interval, bool looping=true, std::size_t cooldown=100, bool useAA=true)
Constructor for Animation class.
glm::vec2 GetSize() const override
Get the size of the current frame.
Definition: Animation.hpp:82
State GetState() const
Get the current state of the animation.
Definition: Animation.hpp:76
std::size_t GetFrameCount() const
Get the total number of frames in the animation.
Definition: Animation.hpp:70
void SetCurrentFrame(std::size_t index)
Set the current frame of the animation.
Useful tools for development.
Definition: Animation.hpp:12
Definition: Drawable.hpp:9