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
Sprite.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_COMPONENTS_SPRITE_HPP_
9#define GALAXY_COMPONENTS_SPRITE_HPP_
10
12#include "galaxy/graphics/Colour.hpp"
13#include "galaxy/graphics/gl/Texture2D.hpp"
14#include "galaxy/graphics/gl/VertexArray.hpp"
15#include "galaxy/math/Rect.hpp"
16
17namespace galaxy
18{
19 namespace components
20 {
24 class Sprite final : public fs::Serializable
25 {
26 public:
30 Sprite();
31
37 Sprite(const nlohmann::json& json);
38
42 Sprite(Sprite&&);
43
48
52 virtual ~Sprite();
53
59 void set_texture(const std::string& texture);
60
67 void set_texture(const std::string& texture, const math::fRect& rect);
68
74 void set_clip(const math::fRect& rect);
75
81 [[nodiscard]]
82 const math::fRect& get_clip() const;
83
89 [[nodiscard]]
90 graphics::Texture2D* get_texture();
91
97 [[nodiscard]]
98 const std::string& get_texture_name() const;
99
105 [[nodiscard]]
106 nlohmann::json serialize() override;
107
113 void deserialize(const nlohmann::json& json) override;
114
115 private:
119 Sprite(const Sprite&) = delete;
120
124 Sprite& operator=(const Sprite&) = delete;
125
126 public:
130 graphics::VertexArray m_vao;
131
135 graphics::Colour m_tint;
136
137 private:
141 graphics::Texture2D* m_texture;
142
146 std::string m_name;
147
151 std::array<graphics::Vertex, 4> m_vertices;
152
156 math::fRect m_clip;
157
161 // void* m_mapped_vbo;
162 };
163 } // namespace components
164} // namespace galaxy
165
166#endif
A sprite is a texture with vertex data.
Definition Sprite.hpp:25
const math::fRect & get_clip() const
Get texture clip.
Definition Sprite.cpp:193
Sprite & operator=(const Sprite &)=delete
Copy assignment operator.
math::fRect m_clip
Texture clip.
Definition Sprite.hpp:156
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition Sprite.cpp:220
graphics::Colour m_tint
Texture tint.
Definition Sprite.hpp:135
const std::string & get_texture_name() const
Texture name.
Definition Sprite.cpp:203
void set_clip(const math::fRect &rect)
Set texture clip.
Definition Sprite.cpp:161
Sprite(const Sprite &)=delete
Copy constructor.
graphics::Texture2D * get_texture()
Get texture.
Definition Sprite.cpp:198
graphics::VertexArray m_vao
Vertex Array Object.
Definition Sprite.hpp:130
Sprite & operator=(Sprite &&)
Move assignment operator.
Definition Sprite.cpp:51
nlohmann::json serialize() override
Serializes object.
Definition Sprite.cpp:208
std::array< graphics::Vertex, 4 > m_vertices
Vertex data.
Definition Sprite.hpp:151
std::string m_name
Texture debug name.
Definition Sprite.hpp:146
virtual ~Sprite()
Destructor.
Definition Sprite.cpp:74
void set_texture(const std::string &texture)
Sets the texture and vertex data.
Definition Sprite.cpp:82
graphics::Texture2D * m_texture
Texture.
Definition Sprite.hpp:141
Allows a class to be serialized.
Timer.hpp galaxy.
Definition Async.hpp:17