Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Public Member Functions | List of all members
gf::Animation Class Reference

An animation. More...

#include <gf/Animation.h>

Public Member Functions

 Animation ()
 Default constructor. More...
 
void addFrame (const Texture &texture, const RectF &bounds, Time duration)
 Add a frame to the animation. More...
 
void addTileset (const Texture &texture, Vector2i layout, Time duration, int frameCount, int frameOffset=0)
 Add a entire tileset to the animation. More...
 
void setLoop (bool enabled)
 Enable or disable the animation loop. More...
 
const TexturegetCurrentTexture () const
 Get the current texture. More...
 
RectF getCurrentBounds () const
 Get the current texture rectangle. More...
 
bool update (Time time)
 Update the state of the animation. More...
 
void reset ()
 Reset the animation. More...
 
bool isFinished () const
 Tell if the animation is finished. More...
 

Detailed Description

An animation.

An animation is a collection of frames that are displayed consecutively during a predefined amount of time.

To display an animation, you need a gf::AnimatedSprite.

See also
gf::AnimatedSprite

Constructor & Destructor Documentation

◆ Animation()

gf::Animation::Animation ( )

Default constructor.

Member Function Documentation

◆ addFrame()

void gf::Animation::addFrame ( const Texture texture,
const RectF bounds,
Time  duration 
)

Add a frame to the animation.

The frame of an animation is defined by the texture of the frame, the texture rectangle (in texture coordinates) and an amount of time.

Parameters
textureThe texture where the sprite is
boundsThe texture rectangle where the sprite is
durationThe amount of time to display the frame

◆ addTileset()

void gf::Animation::addTileset ( const Texture texture,
Vector2i  layout,
Time  duration,
int  frameCount,
int  frameOffset = 0 
)

Add a entire tileset to the animation.

Take all frames of the entire tilset. Each frame is defined the texture rectangle (in texture coordinates) and an amount of time.

Parameters
textureThe texture where the sprite is
layoutLayout of frames
durationThe amount of time to display the frame
frameCountNumber of frames included in tileset
frameOffsetThe frame to start with

◆ getCurrentBounds()

RectF gf::Animation::getCurrentBounds ( ) const

Get the current texture rectangle.

Returns
The current texture rectangle
Exceptions
std::runtime_errorIf the animation is empty

◆ getCurrentTexture()

const Texture & gf::Animation::getCurrentTexture ( ) const

Get the current texture.

Returns
The current texture
Exceptions
std::runtime_errorIf the animation is empty

◆ isFinished()

bool gf::Animation::isFinished ( ) const

Tell if the animation is finished.

◆ reset()

void gf::Animation::reset ( )

Reset the animation.

◆ setLoop()

void gf::Animation::setLoop ( bool  enabled)

Enable or disable the animation loop.

Parameters
enabledTrue to enable the loop otherwise false

◆ update()

bool gf::Animation::update ( Time  time)

Update the state of the animation.

Parameters
timeThe time since the last update
Returns
True if the current frame has changed