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 {
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);
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
106 void SetCurrentFrame(std::size_t index);
107
113 void Draw(const Core::Matrices &data) override;
114
121 void Play();
122
127 void Pause();
128
129private:
133 void Update();
134
135private:
136 std::vector<std::shared_ptr<Util::Image>> m_Frames;
137 State m_State;
138 double m_Interval;
139 bool m_Looping;
140 std::size_t m_Cooldown;
141 bool m_IsChangeFrame = false;
142
143 unsigned long m_CooldownEndTime = 0;
144 double m_TimeBetweenFrameUpdate = 0;
145
146 std::size_t m_Index = 0;
147};
148} // namespace Util
149
150#endif
Definition Drawable.hpp:14
Animation(const std::vector< std::string > &paths, bool play, std::size_t interval, bool looping=true, std::size_t cooldown=100)
Constructor for Animation class.
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
@ PAUSE
Definition Animation.hpp:24
@ ENDED
Definition Animation.hpp:26
@ COOLDOWN
Definition Animation.hpp:25
@ PLAY
Definition Animation.hpp:23
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
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