ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::Animation Class Reference

Steps through frames over time, to use with a SpriteSheet. More...

#include <sprite_sheet.h>

Public Member Functions

 Animation ()=default
 Create an animation with a single frame.
 
 Animation (int frame_count, float frame_duration, bool loop=true)
 Create an animation.
 
void update (float dt)
 Advance the animation.
 
void reset ()
 Go back to the first frame.
 
void set_frame_duration (float frame_duration)
 Set seconds each frame is shown.
 
int get_frame () const
 Get the frame to draw.
 
bool is_finished () const
 Check if a non looping animation has reached its last frame.
 

Private Attributes

int frame_count { 1 }
 
float frame_duration { 0.1F }
 
bool loop { true }
 
float elapsed { 0.0F }
 

Detailed Description

Steps through frames over time, to use with a SpriteSheet.

Definition at line 76 of file sprite_sheet.h.

Constructor & Destructor Documentation

◆ Animation() [1/2]

asw::Animation::Animation ( )
default

Create an animation with a single frame.

◆ Animation() [2/2]

asw::Animation::Animation ( int frame_count,
float frame_duration,
bool loop = true )

Create an animation.

Parameters
frame_countThe number of frames.
frame_durationSeconds each frame is shown.
loopWhether to start over after the last frame.

Definition at line 73 of file sprite_sheet.cpp.

Member Function Documentation

◆ get_frame()

int asw::Animation::get_frame ( ) const

Get the frame to draw.

Returns
The frame index.

Definition at line 102 of file sprite_sheet.cpp.

◆ is_finished()

bool asw::Animation::is_finished ( ) const

Check if a non looping animation has reached its last frame.

Returns
True when finished, always false for looping animations.

Definition at line 113 of file sprite_sheet.cpp.

◆ reset()

void asw::Animation::reset ( )

Go back to the first frame.

Definition at line 92 of file sprite_sheet.cpp.

◆ set_frame_duration()

void asw::Animation::set_frame_duration ( float frame_duration)

Set seconds each frame is shown.

Parameters
frame_durationThe duration in seconds.

Definition at line 97 of file sprite_sheet.cpp.

◆ update()

void asw::Animation::update ( float dt)

Advance the animation.

Parameters
dtThe time in seconds since the last update.

Definition at line 80 of file sprite_sheet.cpp.

Member Data Documentation

◆ elapsed

float asw::Animation::elapsed { 0.0F }
private

Definition at line 122 of file sprite_sheet.h.

◆ frame_count

int asw::Animation::frame_count { 1 }
private

Definition at line 119 of file sprite_sheet.h.

◆ frame_duration

float asw::Animation::frame_duration { 0.1F }
private

Definition at line 120 of file sprite_sheet.h.

◆ loop

bool asw::Animation::loop { true }
private

Definition at line 121 of file sprite_sheet.h.


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