Skip to content

Struct Engine::SpriteComponent

ClassList > Engine > SpriteComponent

Component that holds a Sprite to be rendered.More...

  • #include <SpriteComponent.hpp>

Public Attributes

Type Name
std::string assetPath
The file path or alias used to load the sprite from AssetManager .
bool flipX = false
Mirrors the sprite horizontally, about its own drawn centre.
bool flipY = false
Mirrors the sprite vertically, about its own drawn centre. Purely visual.
float offsetX
Horizontal offset from Position.x to the sprite's top-left corner.
float offsetY
Vertical offset from Position.y to the sprite's top-left corner.
float scaleX = 1.0f
Horizontal scale multiplier of the sprite.
float scaleY = 1.0f
Vertical scale multiplier of the sprite.
std::shared_ptr< Sprite > sprite
Shared pointer to the underlying Sprite .

Public Functions

Type Name
SpriteComponent (std::shared_ptr< Sprite > spritePtr=nullptr, const std::string & path="", float offsetX=0.0f, float offsetY=0.0f, float scaleX=1.0f, float scaleY=1.0f, bool flipX=false, bool flipY=false)
Constructs a SpriteComponent with an optional existing sprite pointer.

Detailed Description

World-space position comes from the Position on the same entity. The sprite is drawn at (Position.x + offsetX, Position.y + offsetY).

Public Attributes Documentation

variable assetPath

The file path or alias used to load the sprite from AssetManager .

std::string Engine::SpriteComponent::assetPath;


variable flipX

Mirrors the sprite horizontally, about its own drawn centre.

bool Engine::SpriteComponent::flipX;

Purely visual: the position, the collider and the children are untouched, so a walker that turns around still needs its rig mirrored (see the Component.flipX Lua helper, which flips the sprite and the subtree).


variable flipY

Mirrors the sprite vertically, about its own drawn centre. Purely visual.

bool Engine::SpriteComponent::flipY;


variable offsetX

Horizontal offset from Position.x to the sprite's top-left corner.

float Engine::SpriteComponent::offsetX;


variable offsetY

Vertical offset from Position.y to the sprite's top-left corner.

float Engine::SpriteComponent::offsetY;


variable scaleX

Horizontal scale multiplier of the sprite.

float Engine::SpriteComponent::scaleX;


variable scaleY

Vertical scale multiplier of the sprite.

float Engine::SpriteComponent::scaleY;


variable sprite

Shared pointer to the underlying Sprite .

std::shared_ptr<Sprite> Engine::SpriteComponent::sprite;


Public Functions Documentation

function SpriteComponent

Constructs a SpriteComponent with an optional existing sprite pointer.

inline Engine::SpriteComponent::SpriteComponent (
    std::shared_ptr< Sprite > spritePtr=nullptr,
    const std::string & path="",
    float offsetX=0.0f,
    float offsetY=0.0f,
    float scaleX=1.0f,
    float scaleY=1.0f,
    bool flipX=false,
    bool flipY=false
) 

Parameters:

  • spritePtr A shared pointer to an existing Sprite. Defaults to nullptr.
  • path The file path or alias of the asset.
  • offsetX Offset from entity position on X.
  • offsetY Offset from entity position on Y.
  • scaleX Horizontal scale. Defaults to 1.0f.
  • scaleY Vertical scale. Defaults to 1.0f.
  • flipX Mirror horizontally. Defaults to false.
  • flipY Mirror vertically. Defaults to false.


The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Components/SpriteComponent.hpp