R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::Sprite Class Reference

Component representing a visual sprite from a texture. More...

#include <Sprite.hpp>

Inheritance diagram for ecs::Sprite:
Inheritance graph
Collaboration diagram for ecs::Sprite:
Collaboration graph

Public Member Functions

 Sprite (const std::string &textureKey, Rectangle sourceRect, float scale=1.0f, float rotation=0.0f, bool flipX=false, bool flipY=false, int layer=0)
 Constructor with all sprite parameters.
 
 ~Sprite () override=default
 
std::string getTextureKey () const
 Get the texture key.
 
Rectangle getSourceRect () const
 Get the source rectangle.
 
float getScale () const
 Get the scale factor.
 
float getRotation () const
 Get the rotation angle.
 
bool isFlippedX () const
 Check if horizontally flipped.
 
bool isFlippedY () const
 Check if vertically flipped.
 
int getLayer () const
 Get the rendering layer.
 
void setTextureKey (const std::string &textureKey)
 Set the texture key.
 
void setSourceRect (Rectangle sourceRect)
 Set the source rectangle.
 
void setScale (float scale)
 Set the scale factor.
 
void setRotation (float rotation)
 Set the rotation angle.
 
void setFlipX (bool flipX)
 Set horizontal flip state.
 
void setFlipY (bool flipY)
 Set vertical flip state.
 
void setLayer (int layer)
 Set the rendering layer.
 
ComponentType getType () const override
 Get the component type ID.
 
- Public Member Functions inherited from ecs::IComponent
virtual ~IComponent ()=default
 Virtual destructor.
 

Private Attributes

std::string _textureKey
 Texture identifier (e.g., "r-typesheet1")
 
Rectangle _sourceRect
 Source rectangle in the texture.
 
float _scale
 Scale factor (1.0 = original size)
 
float _rotation
 Rotation angle in degrees.
 
bool _flipX
 Horizontal flip flag.
 
bool _flipY
 Vertical flip flag.
 
int _layer
 Rendering layer for Z-ordering.
 

Detailed Description

Component representing a visual sprite from a texture.

Stores visual rendering data including texture identifier, source rectangle, scale, rotation, flip states, and rendering layer for Z-ordering.

Definition at line 32 of file Sprite.hpp.

Constructor & Destructor Documentation

◆ Sprite()

ecs::Sprite::Sprite ( const std::string &  textureKey,
Rectangle  sourceRect,
float  scale = 1.0f,
float  rotation = 0.0f,
bool  flipX = false,
bool  flipY = false,
int  layer = 0 
)
inline

Constructor with all sprite parameters.

Parameters
textureKeyTexture identifier (e.g., "r-typesheet1")
sourceRectSource rectangle in the texture
scaleScale factor (1.0 = original size)
rotationRotation angle in degrees
flipXHorizontal flip flag
flipYVertical flip flag
layerRendering layer for Z-ordering

Definition at line 44 of file Sprite.hpp.

◆ ~Sprite()

ecs::Sprite::~Sprite ( )
overridedefault

Member Function Documentation

◆ getLayer()

int ecs::Sprite::getLayer ( ) const
inline

Get the rendering layer.

Returns
int The Z-ordering layer value.

Definition at line 96 of file Sprite.hpp.

References _layer.

◆ getRotation()

float ecs::Sprite::getRotation ( ) const
inline

Get the rotation angle.

Returns
float The rotation in degrees.

Definition at line 78 of file Sprite.hpp.

References _rotation.

◆ getScale()

float ecs::Sprite::getScale ( ) const
inline

Get the scale factor.

Returns
float The scale value.

Definition at line 72 of file Sprite.hpp.

References _scale.

◆ getSourceRect()

Rectangle ecs::Sprite::getSourceRect ( ) const
inline

Get the source rectangle.

Returns
Rectangle The source rectangle in the texture.

Definition at line 66 of file Sprite.hpp.

References _sourceRect.

Referenced by Server::_serializeEntity().

◆ getTextureKey()

std::string ecs::Sprite::getTextureKey ( ) const
inline

Get the texture key.

Returns
std::string The texture identifier.

Definition at line 60 of file Sprite.hpp.

References _textureKey.

◆ getType()

ComponentType ecs::Sprite::getType ( ) const
inlineoverridevirtual

Get the component type ID.

Returns
ComponentType Unique ID for Sprite component.

Implements ecs::IComponent.

Definition at line 144 of file Sprite.hpp.

◆ isFlippedX()

bool ecs::Sprite::isFlippedX ( ) const
inline

Check if horizontally flipped.

Returns
bool True if flipped on X axis.

Definition at line 84 of file Sprite.hpp.

References _flipX.

◆ isFlippedY()

bool ecs::Sprite::isFlippedY ( ) const
inline

Check if vertically flipped.

Returns
bool True if flipped on Y axis.

Definition at line 90 of file Sprite.hpp.

References _flipY.

◆ setFlipX()

void ecs::Sprite::setFlipX ( bool  flipX)
inline

Set horizontal flip state.

Parameters
flipXTrue to flip horizontally

Definition at line 126 of file Sprite.hpp.

References _flipX.

◆ setFlipY()

void ecs::Sprite::setFlipY ( bool  flipY)
inline

Set vertical flip state.

Parameters
flipYTrue to flip vertically

Definition at line 132 of file Sprite.hpp.

References _flipY.

◆ setLayer()

void ecs::Sprite::setLayer ( int  layer)
inline

Set the rendering layer.

Parameters
layerNew layer value for Z-ordering

Definition at line 138 of file Sprite.hpp.

References _layer.

◆ setRotation()

void ecs::Sprite::setRotation ( float  rotation)
inline

Set the rotation angle.

Parameters
rotationNew rotation in degrees

Definition at line 120 of file Sprite.hpp.

References _rotation.

◆ setScale()

void ecs::Sprite::setScale ( float  scale)
inline

Set the scale factor.

Parameters
scaleNew scale value

Definition at line 114 of file Sprite.hpp.

References _scale.

◆ setSourceRect()

void ecs::Sprite::setSourceRect ( Rectangle  sourceRect)
inline

Set the source rectangle.

Parameters
sourceRectNew source rectangle

Definition at line 108 of file Sprite.hpp.

References _sourceRect.

Referenced by ecs::AnimationSystem::update().

◆ setTextureKey()

void ecs::Sprite::setTextureKey ( const std::string &  textureKey)
inline

Set the texture key.

Parameters
textureKeyNew texture identifier

Definition at line 102 of file Sprite.hpp.

References _textureKey.

Member Data Documentation

◆ _flipX

bool ecs::Sprite::_flipX
private

Horizontal flip flag.

Definition at line 151 of file Sprite.hpp.

Referenced by isFlippedX(), and setFlipX().

◆ _flipY

bool ecs::Sprite::_flipY
private

Vertical flip flag.

Definition at line 152 of file Sprite.hpp.

Referenced by isFlippedY(), and setFlipY().

◆ _layer

int ecs::Sprite::_layer
private

Rendering layer for Z-ordering.

Definition at line 153 of file Sprite.hpp.

Referenced by getLayer(), and setLayer().

◆ _rotation

float ecs::Sprite::_rotation
private

Rotation angle in degrees.

Definition at line 150 of file Sprite.hpp.

Referenced by getRotation(), and setRotation().

◆ _scale

float ecs::Sprite::_scale
private

Scale factor (1.0 = original size)

Definition at line 149 of file Sprite.hpp.

Referenced by getScale(), and setScale().

◆ _sourceRect

Rectangle ecs::Sprite::_sourceRect
private

Source rectangle in the texture.

Definition at line 148 of file Sprite.hpp.

Referenced by getSourceRect(), and setSourceRect().

◆ _textureKey

std::string ecs::Sprite::_textureKey
private

Texture identifier (e.g., "r-typesheet1")

Definition at line 147 of file Sprite.hpp.

Referenced by getTextureKey(), and setTextureKey().


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