Skip to content

Class Engine::Sprite

ClassList > Engine > Sprite

Engine wrapper for a visual sprite, utilizing raylib::Texture to handle rendering, scaling, and rotation.

  • #include <Sprites.hpp>

Public Functions

Type Name
void Draw (const raylib::Vector2 & position)
Draws the sprite to the screen at the given position using its current properties (scale, rotation, source rect).
void Draw (const raylib::Vector2 & position, const raylib::Color & tint)
Draws the sprite with a tint color (e.g. a faded alpha for opacity). Per-call tint: safe for textures shared between entities.
float GetRotation () const
Gets the rotation angle of the sprite in degrees.
const raylib::Vector2 & GetScale () const
Gets the scale factor of the sprite.
const raylib::Rectangle & GetSourceRect () const
Gets the source rectangle used for drawing a specific part of the texture (useful for sprite sheets).
const raylib::Texture & GetTexture () const
Gets the underlying raylib texture.
void SetRotation (float rot)
Sets the rotation angle of the sprite.
void SetScale (const raylib::Vector2 & scale)
Sets the scale factor of the sprite.
void SetSourceRect (const raylib::Rectangle & rect)
Sets the source rectangle used for drawing a specific part of the texture. Negative width or height is allowed and flips the sprite on that axis.
Sprite (const std::string & path)
Constructs a new Sprite object by loading a texture from a file.

Public Functions Documentation

function Draw [½]

Draws the sprite to the screen at the given position using its current properties (scale, rotation, source rect).

void Engine::Sprite::Draw (
    const raylib::Vector2 & position
) 

Parameters:

  • position The world-space position to draw the sprite at.

function Draw [2/2]

Draws the sprite with a tint color (e.g. a faded alpha for opacity). Per-call tint: safe for textures shared between entities.

void Engine::Sprite::Draw (
    const raylib::Vector2 & position,
    const raylib::Color & tint
) 

Parameters:

  • position The world-space position to draw the sprite at.
  • tint Color multiplier applied to every pixel.

function GetRotation

Gets the rotation angle of the sprite in degrees.

float Engine::Sprite::GetRotation () const

Returns:

The rotation angle.


function GetScale

Gets the scale factor of the sprite.

const raylib::Vector2 & Engine::Sprite::GetScale () const

Returns:

Constant reference to the scale vector.


function GetSourceRect

Gets the source rectangle used for drawing a specific part of the texture (useful for sprite sheets).

const raylib::Rectangle & Engine::Sprite::GetSourceRect () const

Returns:

Constant reference to the source raylib::Rectangle.


function GetTexture

Gets the underlying raylib texture.

const raylib::Texture & Engine::Sprite::GetTexture () const

Returns:

Constant reference to the raylib::Texture.


function SetRotation

Sets the rotation angle of the sprite.

void Engine::Sprite::SetRotation (
    float rot
) 

Parameters:

  • rot The new rotation angle in degrees.

function SetScale

Sets the scale factor of the sprite.

void Engine::Sprite::SetScale (
    const raylib::Vector2 & scale
) 

Parameters:

  • scale The new scale vector.

Exception:

  • ErrorAsset If either component is less than or equal to 0.

function SetSourceRect

Sets the source rectangle used for drawing a specific part of the texture. Negative width or height is allowed and flips the sprite on that axis.

void Engine::Sprite::SetSourceRect (
    const raylib::Rectangle & rect
) 

Parameters:

  • rect The new source rectangle.

Exception:

  • ErrorAsset If width or height is 0, or if the rectangle lies outside the texture.

function Sprite

Constructs a new Sprite object by loading a texture from a file.

Engine::Sprite::Sprite (
    const std::string & path
) 

Parameters:

  • path The file path to the image file.


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