Gamedev Framework (gf)  0.17.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...
 
void addTileset (const Texture &texture, const Vector2f &frameSize, const Vector2i &layout, int nbFrames, Time duration)
 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...
 

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,
const Vector2f frameSize,
const Vector2i layout,
int  nbFrames,
Time  duration 
)

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
frameSizeThe frame texture normalized size
layoutLayout of frames
nbFramesNumber of frames included in tileset
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

◆ 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