Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::ecs::Animation Struct Reference

Frames of the entity's Sprite shown in turn, at a steady rate. More...

#include <aegis2d/ecs/components.hpp>

Public Member Functions

constexpr float duration () const noexcept
 Length of the clip.
 
constexpr std::uint32_t frame () const noexcept
 Frame to show now.
 
constexpr bool finished () const noexcept
 Tells whether a clip that does not loop has shown its last frame long enough.
 

Public Attributes

std::uint32_t first = 0
 First frame of the clip in the sprite sheet.
 
std::uint32_t count = 1
 Number of frames of the clip; 0 counts as 1.
 
float frame_time = 0.1F
 Seconds each frame stays on screen; 0 or less keeps the first frame.
 
bool loop = true
 true to start again after the last frame, false to stop on it.
 
float elapsed = 0.0F
 Seconds into the clip; kept below duration() while looping.
 

Detailed Description

Frames of the entity's Sprite shown in turn, at a steady rate.

The clip is the frames first to first + count - 1 of the texture's sprite sheet (render::SpriteSheet). ecs::animate_sprites() advances elapsed by each tick and sets Sprite::frame to frame(): the frame depends only on the time spent, so the animation runs at the same speed at any tick rate. A looping clip starts again after its last frame; another stays on its last frame, finished(). Starting entities at different elapsed values keeps them from animating in step.

Member Function Documentation

◆ duration()

constexpr float aegis2d::ecs::Animation::duration ( ) const
inlineconstexprnoexcept

Length of the clip.

Returns
count * frame_time, in seconds.

◆ finished()

constexpr bool aegis2d::ecs::Animation::finished ( ) const
inlineconstexprnoexcept

Tells whether a clip that does not loop has shown its last frame long enough.

Returns
true once elapsed reaches duration() without loop.

◆ frame()

constexpr std::uint32_t aegis2d::ecs::Animation::frame ( ) const
inlineconstexprnoexcept

Frame to show now.

Returns
A frame from first to first + count - 1.

Member Data Documentation

◆ count

std::uint32_t aegis2d::ecs::Animation::count = 1

Number of frames of the clip; 0 counts as 1.

◆ elapsed

float aegis2d::ecs::Animation::elapsed = 0.0F

Seconds into the clip; kept below duration() while looping.

◆ first

std::uint32_t aegis2d::ecs::Animation::first = 0

First frame of the clip in the sprite sheet.

◆ frame_time

float aegis2d::ecs::Animation::frame_time = 0.1F

Seconds each frame stays on screen; 0 or less keeps the first frame.

◆ loop

bool aegis2d::ecs::Animation::loop = true

true to start again after the last frame, false to stop on it.


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