Skip to content

Struct Engine::Animation

ClassList > Engine > Animation

ECS Component managing animation clip collections and runtime playback state. More...

  • #include <Animation.hpp>

Public Attributes

Type Name
std::unordered_map< std::string, AnimationClip > clips
std::string currentAnimation = ""
std::size_t currentFrame = 0
bool flipX = false
bool flipY = false
bool isPlaying = true
float offsetX = 0.0f
float offsetY = 0.0f
float scaleX = 1.0f
float scaleY = 1.0f
std::vector< std::shared_ptr< Sprite > > sprites
float timer = 0.0f

Public Functions

Type Name
Animation () = default
Default constructor.
Animation (std::vector< std::string > paths, float frameDuration=0.1f, bool loop=true, float offsetX=0.0f, float offsetY=0.0f, float scaleX=1.0f, float scaleY=1.0f, bool flipX=false, bool flipY=false, const std::string & clipName="Idle")
Helper constructor initializing an Animation component with a multi-file clip.
Animation (const std::string & sheetPath, float frameWidth, float frameHeight, std::size_t totalFrames=0, float frameDuration=0.1f, bool loop=true, float offsetX=0.0f, float offsetY=0.0f, float scaleX=1.0f, float scaleY=1.0f, bool flipX=false, bool flipY=false, const std::string & clipName="Idle")
Helper constructor initializing an Animation component with a uniform grid clip.
Animation (const std::string & sheetPath, std::vector< FrameData > frames, float frameDuration=0.1f, bool loop=true, float offsetX=0.0f, float offsetY=0.0f, float scaleX=1.0f, float scaleY=1.0f, bool flipX=false, bool flipY=false, const std::string & clipName="Idle")
Helper constructor initializing an Animation component with explicitFrameData .
const AnimationClip * GetCurrentClip () const
Gets a const pointer to the currently active AnimationClip .
AnimationClip * GetCurrentClip ()
Gets a mutable pointer to the currently active AnimationClip .
bool Play (const std::string & clipName, bool restartIfSame=false)
Switches active animation state and resets playback counters.

Detailed Description

Contains all animation clips assigned to an entity, runtime playback counters, texture instance caches, and spatial transformations (scale, offset, mirroring).

Public Attributes Documentation

variable clips

std::unordered_map<std::string, AnimationClip> Engine::Animation::clips;

Map of clip names to their static configuration.


variable currentAnimation

std::string Engine::Animation::currentAnimation;

Key of the currently active animation clip.


variable currentFrame

std::size_t Engine::Animation::currentFrame;

Index of the currently displayed frame.


variable flipX

bool Engine::Animation::flipX;

Mirrors sprite horizontally when rendered.


variable flipY

bool Engine::Animation::flipY;

Mirrors sprite vertically when rendered.


variable isPlaying

bool Engine::Animation::isPlaying;

Controls active playback advancement.


variable offsetX

float Engine::Animation::offsetX;

Horizontal anchor offset added to Entity Position.x.


variable offsetY

float Engine::Animation::offsetY;

Vertical anchor offset added to Entity Position.y.


variable scaleX

float Engine::Animation::scaleX;

Horizontal scale multiplier.


variable scaleY

float Engine::Animation::scaleY;

Vertical scale multiplier.


variable sprites

std::vector<std::shared_ptr<Sprite> > Engine::Animation::sprites;

Cached runtime sprite instances for active asset paths.


variable timer

float Engine::Animation::timer;

Accumulated delta time for current frame step.


Public Functions Documentation

function Animation [¼]

Default constructor.

Engine::Animation::Animation () = default


function Animation [2/4]

Helper constructor initializing an Animation component with a multi-file clip.

Engine::Animation::Animation (
    std::vector< std::string > paths,
    float frameDuration=0.1f,
    bool loop=true,
    float offsetX=0.0f,
    float offsetY=0.0f,
    float scaleX=1.0f,
    float scaleY=1.0f,
    bool flipX=false,
    bool flipY=false,
    const std::string & clipName="Idle"
) 

Parameters:

  • paths List of image file paths.
  • frameDuration Time per frame in seconds.
  • loop Enables continuous looping.
  • offsetX World position horizontal offset.
  • offsetY World position vertical offset.
  • scaleX Horizontal scale factor.
  • scaleY Vertical scale factor.
  • flipX Horizontal flip flag.
  • flipY Vertical flip flag.
  • clipName Default clip identifier name.

function Animation [¾]

Helper constructor initializing an Animation component with a uniform grid clip.

Engine::Animation::Animation (
    const std::string & sheetPath,
    float frameWidth,
    float frameHeight,
    std::size_t totalFrames=0,
    float frameDuration=0.1f,
    bool loop=true,
    float offsetX=0.0f,
    float offsetY=0.0f,
    float scaleX=1.0f,
    float scaleY=1.0f,
    bool flipX=false,
    bool flipY=false,
    const std::string & clipName="Idle"
) 

Parameters:

  • sheetPath Path to spritesheet image.
  • frameWidth Cell frame width in pixels.
  • frameHeight Cell frame height in pixels.
  • totalFrames Total frame count.
  • frameDuration Time per frame in seconds.
  • loop Enables continuous looping.
  • offsetX World position horizontal offset.
  • offsetY World position vertical offset.
  • scaleX Horizontal scale factor.
  • scaleY Vertical scale factor.
  • flipX Horizontal flip flag.
  • flipY Vertical flip flag.
  • clipName Default clip identifier name.

function Animation [4/4]

Helper constructor initializing an Animation component with explicitFrameData .

Engine::Animation::Animation (
    const std::string & sheetPath,
    std::vector< FrameData > frames,
    float frameDuration=0.1f,
    bool loop=true,
    float offsetX=0.0f,
    float offsetY=0.0f,
    float scaleX=1.0f,
    float scaleY=1.0f,
    bool flipX=false,
    bool flipY=false,
    const std::string & clipName="Idle"
) 

Parameters:

  • sheetPath Path to texture atlas.
  • frames Array of FrameData frame specifications.
  • frameDuration Time per frame in seconds.
  • loop Enables continuous looping.
  • offsetX World position horizontal offset.
  • offsetY World position vertical offset.
  • scaleX Horizontal scale factor.
  • scaleY Vertical scale factor.
  • flipX Horizontal flip flag.
  • flipY Vertical flip flag.
  • clipName Default clip identifier name.

function GetCurrentClip [½]

Gets a const pointer to the currently active AnimationClip .

const AnimationClip * Engine::Animation::GetCurrentClip () const

Returns:

Pointer to active AnimationClip, or nullptr if no valid clip is active.


function GetCurrentClip [2/2]

Gets a mutable pointer to the currently active AnimationClip .

AnimationClip * Engine::Animation::GetCurrentClip () 

Returns:

Pointer to active AnimationClip, or nullptr if no valid clip is active.


function Play

Switches active animation state and resets playback counters.

bool Engine::Animation::Play (
    const std::string & clipName,
    bool restartIfSame=false
) 

Parameters:

  • clipName Name key of the clip to play.
  • restartIfSame If true, restarts playback from frame 0 even if already playing.

Returns:

True if the requested clip exists and was activated, false otherwise.



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