galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Animation.hpp
Go to the documentation of this file.
1
8
9#ifndef GALAXY_GRAPHICS_ANIM_ANIMATION_HPP_
10#define GALAXY_GRAPHICS_ANIM_ANIMATION_HPP_
11
12#include <nlohmann/json_fwd.hpp>
13
15#include "galaxy/meta/Memory.hpp"
16
17namespace galaxy
18{
19 namespace graphics
20 {
21
22 // want to load a series of frames based on a texture. each frame should have drawable rect offset + time per frame
23
27 class Animation final
28 {
29 public:
33 Animation();
34
39
44
48 Animation(const Animation&);
49
54
58 ~Animation();
59
67 [[nodiscard]]
68 bool load(const std::string& file);
69
75 void set_frames(const nlohmann::json& json);
76
82 void set_frames(const meta::vector<Frame>& frames);
83
87 void next();
88
92 void prev();
93
97 void restart();
98
104 [[nodiscard]]
105 Frame& current();
106
112 [[nodiscard]]
113 std::size_t total() const;
114
120 [[nodiscard]]
121 std::size_t index() const;
122
128 [[nodiscard]]
129 meta::vector<Frame>& frames();
130
131 public:
136 double m_speed;
137
141 std::string m_name;
142
143 private:
147 std::size_t m_index;
148
152 meta::vector<Frame> m_frames;
153 };
154 } // namespace graphics
155} // namespace galaxy
156
157#endif
2D animation information.
Definition Animation.hpp:28
double m_speed
Speed of the animation. Multiplier, so 1.0f is regular speed.
void prev()
Go back to the previous frame.
bool load(const std::string &file)
Load a json file from VFS and set frames from that.
Definition Animation.cpp:71
std::size_t index() const
Get current frame index.
meta::vector< Frame > & frames()
Get the frames.
std::size_t m_index
Index of the current active frame.
Animation & operator=(Animation &&)
Move assignment operator.
Definition Animation.cpp:33
void set_frames(const nlohmann::json &json)
Loads frames from json object.
Definition Animation.cpp:88
std::string m_name
Animation name.
std::size_t total() const
Get total frames.
void restart()
Sets animation back to beginning.
meta::vector< Frame > m_frames
Frames belonging to this animation.
void next()
Advance to the next frame.
Frame & current()
Get currently active frame.
Animated.cpp galaxy.
Definition Animated.cpp:16
Single frame of an animation.
Definition Frame.hpp:21