Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
Sprite Class Referencefinal

Component that represents a 2D sprite to be rendered. The Sprite component holds a reference to a Texture and includes properties for flipping, sorting, ordering, and color modulation. It can be treated as a wrapper around a texture with additional rendering properties that go beyond just the texture itself. More...

#include <sprite.h>

Inheritance diagram for Sprite:
[legend]

Public Member Functions

 Sprite (const std::string &sprite, Color color, bool flip_x, bool flip_y, int sorting_layer, int ordering_layer)
 
bool flip_x () const
 
Spriteflip_x (bool val)
 
bool flip_y () const
 
Spriteflip_y (bool val)
 
int sorting_layer () const
 
Spritesorting_layer (int val)
 
int ordering_layer () const
 
Spriteordering_layer (int val)
 
Color color () const
 
Spritecolor (Color color)
 
const Texturetexture () const
 
Spritetexture (const std::string &name)
 
Spritetexture (Texture &texture)
 
void update (float dt) override
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
- Public Member Functions inherited from Renderable
 Renderable ()
 
 Renderable (int layer)
 
 ~Renderable () override=default
 
Renderableorder_in_layer (int layer)
 
int order_in_layer () const
 
void set_render_strategy (Component &component)
 
virtual IRenderingStrategyrender_strategy () const
 
Renderabledisable_draw () noexcept
 
Renderableenable_draw () noexcept
 
bool should_draw () const noexcept
 
- Public Member Functions inherited from Component
 Component ()
 
virtual ~Component ()=default
 
bool active () const noexcept
 Checks if the component is active.
 
Componentactive (bool value) noexcept
 
bool marked_for_deletion () const noexcept
 Activates the component.
 
Componentmark_for_deletion () noexcept
 
virtual void on_attach ()
 Called when the component is attached to a GameObject.
 
virtual void on_detach ()
 Called when the component is detached from a GameObject.
 
virtual void on_serialize (std::vector< uint8_t > &) const
 Serializes the component's state into a byte array.
 
virtual void on_deserialize (const std::vector< uint8_t > &, size_t &)
 Deserializes the component's state from a byte array.
 
const std::optional< std::reference_wrapper< GameObject > > & parent () const noexcept
 Gets the parent GameObject of this component.
 
std::optional< std::reference_wrapper< GameObject > > & parent () noexcept
 Gets the parent GameObject of this component.
 
Componentparent (GameObject &parent)
 
Componentparent (std::nullopt_t nullopt)
 
size_t add_on_attach (const std::function< void(Component &)> &action)
 Retrieves the type information of the component.
 
void remove_on_attach (size_t index)
 
size_t add_on_detach (const std::function< void(Component &)> &action)
 Adds an action to be performed when the component is attached.
 
void remove_on_detach (size_t index)
 

Additional Inherited Members

- Protected Attributes inherited from Renderable
std::unique_ptr< IRenderingStrategyrender_strategy_
 
int ordering_layer_ = 0
 
bool draw {true}
 

Detailed Description

Component that represents a 2D sprite to be rendered. The Sprite component holds a reference to a Texture and includes properties for flipping, sorting, ordering, and color modulation. It can be treated as a wrapper around a texture with additional rendering properties that go beyond just the texture itself.

Usage:

  • Create a Sprite component with a texture name and desired properties.
  • Attach the Sprite to a GameObject to have it rendered.
  • Modify properties such as flip_x, flip_y, sorting_layer, ordering_layer, and color as needed.
    Note
    Ensure the specified texture exists in the asset resource.

Constructor & Destructor Documentation

◆ Sprite()

Sprite::Sprite ( const std::string &  sprite,
Color  color,
bool  flip_x,
bool  flip_y,
int  sorting_layer,
int  ordering_layer 
)

Member Function Documentation

◆ color() [1/2]

Color Sprite::color ( ) const

◆ color() [2/2]

Sprite & Sprite::color ( Color  color)

◆ flip_x() [1/2]

bool Sprite::flip_x ( ) const

◆ flip_x() [2/2]

Sprite & Sprite::flip_x ( bool  val)

◆ flip_y() [1/2]

bool Sprite::flip_y ( ) const

◆ flip_y() [2/2]

Sprite & Sprite::flip_y ( bool  val)

◆ ordering_layer() [1/2]

int Sprite::ordering_layer ( ) const

◆ ordering_layer() [2/2]

Sprite & Sprite::ordering_layer ( int  val)

◆ sorting_layer() [1/2]

int Sprite::sorting_layer ( ) const

◆ sorting_layer() [2/2]

Sprite & Sprite::sorting_layer ( int  val)

◆ texture() [1/3]

const Texture & Sprite::texture ( ) const

◆ texture() [2/3]

Sprite & Sprite::texture ( const std::string &  name)

◆ texture() [3/3]

Sprite & Sprite::texture ( Texture texture)

◆ type_name()

std::string Sprite::type_name ( ) const
overridevirtual

Provides a consistent type name for the component.

Returns
A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.

Reimplemented from Renderable.

◆ update()

void Sprite::update ( float  dt)
overridevirtual

Implements Component.


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