Gamedev Framework (gf)  0.12.0
A C++14 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...
 
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...
 

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

◆ 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

◆ 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