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
galaxy::components::Sprite Class Referencefinal

A sprite is a texture with vertex data. More...

#include <Sprite.hpp>

+ Inheritance diagram for galaxy::components::Sprite:
+ Collaboration diagram for galaxy::components::Sprite:

Public Member Functions

 Sprite ()
 Constructor.
 
 Sprite (const nlohmann::json &json)
 JSON constructor.
 
 Sprite (Sprite &&)
 Move constructor.
 
Spriteoperator= (Sprite &&)
 Move assignment operator.
 
virtual ~Sprite ()
 Destructor.
 
void set_texture (const std::string &texture)
 Sets the texture and vertex data.
 
void set_texture (const std::string &texture, const math::fRect &rect)
 Sets the texture and vertex data.
 
void set_clip (const math::fRect &rect)
 Set texture clip.
 
const math::fRect & get_clip () const
 Get texture clip.
 
graphics::Texture2D * get_texture ()
 Get texture.
 
const std::string & get_texture_name () const
 Texture name.
 
nlohmann::json serialize () override
 Serializes object.
 
void deserialize (const nlohmann::json &json) override
 Deserializes from object.
 
- Public Member Functions inherited from galaxy::fs::Serializable
virtual ~Serializable ()
 Destructor.
 
virtual Serializableoperator= (Serializable &&)=default
 Move assignment operator.
 
virtual Serializableoperator= (const Serializable &)=default
 Copy assignment operator.
 

Public Attributes

graphics::VertexArray m_vao
 Vertex Array Object.
 
graphics::Colour m_tint
 Texture tint.
 

Private Member Functions

 Sprite (const Sprite &)=delete
 Copy constructor.
 
Spriteoperator= (const Sprite &)=delete
 Copy assignment operator.
 

Private Attributes

graphics::Texture2D * m_texture
 Texture.
 
std::string m_name
 Texture debug name.
 
std::array< graphics::Vertex, 4 > m_vertices
 Vertex data.
 
math::fRect m_clip
 Texture clip.
 

Additional Inherited Members

- Protected Member Functions inherited from galaxy::fs::Serializable
 Serializable ()
 Constructor.
 

Detailed Description

A sprite is a texture with vertex data.

Definition at line 24 of file Sprite.hpp.

Constructor & Destructor Documentation

◆ Sprite() [1/4]

galaxy::components::Sprite::Sprite ( )

Constructor.

Definition at line 19 of file Sprite.cpp.

◆ Sprite() [2/4]

galaxy::components::Sprite::Sprite ( const nlohmann::json & json)

JSON constructor.

Parameters
jsonJSON defining object.

Definition at line 26 of file Sprite.cpp.

+ Here is the call graph for this function:

◆ Sprite() [3/4]

galaxy::components::Sprite::Sprite ( Sprite && s)

Move constructor.

Definition at line 32 of file Sprite.cpp.

◆ ~Sprite()

galaxy::components::Sprite::~Sprite ( )
virtual

Destructor.

Definition at line 74 of file Sprite.cpp.

◆ Sprite() [4/4]

galaxy::components::Sprite::Sprite ( const Sprite & )
privatedelete

Copy constructor.

Member Function Documentation

◆ operator=() [1/2]

Sprite & galaxy::components::Sprite::operator= ( Sprite && s)

Move assignment operator.

Definition at line 51 of file Sprite.cpp.

◆ set_texture() [1/2]

void galaxy::components::Sprite::set_texture ( const std::string & texture)

Sets the texture and vertex data.

Parameters
textureTexture file in VFS.

Definition at line 82 of file Sprite.cpp.

+ Here is the caller graph for this function:

◆ set_texture() [2/2]

void galaxy::components::Sprite::set_texture ( const std::string & texture,
const math::fRect & rect )

Sets the texture and vertex data.

Parameters
textureTexture file in VFS.
rectCustom region on a texture to render from.

Definition at line 112 of file Sprite.cpp.

◆ set_clip()

void galaxy::components::Sprite::set_clip ( const math::fRect & rect)

Set texture clip.

Parameters
rectCoords on sprite to clip to.

Definition at line 161 of file Sprite.cpp.

◆ get_clip()

const math::fRect & galaxy::components::Sprite::get_clip ( ) const
nodiscard

Get texture clip.

Returns
Const reference to sprite clip.

Definition at line 193 of file Sprite.cpp.

◆ get_texture()

graphics::Texture2D * galaxy::components::Sprite::get_texture ( )
nodiscard

Get texture.

Returns
Pointer. DO NOT STORE THIS.

Definition at line 198 of file Sprite.cpp.

◆ get_texture_name()

const std::string & galaxy::components::Sprite::get_texture_name ( ) const
nodiscard

Texture name.

Returns
Const string ref.

Definition at line 203 of file Sprite.cpp.

◆ serialize()

nlohmann::json galaxy::components::Sprite::serialize ( )
nodiscardoverridevirtual

Serializes object.

Returns
JSON object containing data to be serialized.

Implements galaxy::fs::Serializable.

Definition at line 208 of file Sprite.cpp.

◆ deserialize()

void galaxy::components::Sprite::deserialize ( const nlohmann::json & json)
overridevirtual

Deserializes from object.

Parameters
jsonJson object to retrieve data from.

Implements galaxy::fs::Serializable.

Definition at line 220 of file Sprite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [2/2]

Sprite & galaxy::components::Sprite::operator= ( const Sprite & )
privatedelete

Copy assignment operator.

Member Data Documentation

◆ m_vao

graphics::VertexArray galaxy::components::Sprite::m_vao

Vertex Array Object.

Definition at line 130 of file Sprite.hpp.

◆ m_tint

graphics::Colour galaxy::components::Sprite::m_tint

Texture tint.

Definition at line 135 of file Sprite.hpp.

◆ m_texture

graphics::Texture2D* galaxy::components::Sprite::m_texture
private

Texture.

Definition at line 141 of file Sprite.hpp.

◆ m_name

std::string galaxy::components::Sprite::m_name
private

Texture debug name.

Definition at line 146 of file Sprite.hpp.

◆ m_vertices

std::array<graphics::Vertex, 4> galaxy::components::Sprite::m_vertices
private

Vertex data.

Definition at line 151 of file Sprite.hpp.

◆ m_clip

math::fRect galaxy::components::Sprite::m_clip
private

Texture clip.

Definition at line 156 of file Sprite.hpp.


The documentation for this class was generated from the following files: