Public Types | Public Member Functions | Static Public Member Functions | List of all members
ime::Animation Class Reference

A frame based animation. More...

#include <Animation.h>

Public Types

enum  Direction { Direction::Forward, Direction::Reverse, Direction::Alternate_Forward, Direction::Alternate_Reverse }
 The playing direction of the animation. More...
 
using Frame = UIntRect
 Animation Frame. More...
 
using Ptr = std::shared_ptr< Animation >
 Shared animation pointer. More...
 

Public Member Functions

 Animation (const std::string &name, const SpriteSheet &spriteSheet, Time duration=Time::Zero)
 Construct an animation. More...
 
const SpriteSheetgetSpriteSheet () const
 Get the spritesheet used by the animation. More...
 
void setRepeatCount (int count)
 Enable or disable animation repetition. More...
 
int getRepeatCount () const
 Get the number of times the animation is repeated before completing. More...
 
bool isRepeating () const
 Check if the animation is repeating or not. More...
 
void setDuration (Time duration)
 Set the new duration of the animation. More...
 
Time getDuration () const
 Get the duration of the animation. More...
 
void setFrameRate (unsigned int frameRate)
 Set the frame rate playback of the animation. More...
 
unsigned int getFrameRate () const
 Get the animations playback frame rate. More...
 
void setDirection (Direction direction)
 Set the direction in which the animation should be played. More...
 
Direction getDirection () const
 Get the animations playing direction. More...
 
const std::string & getName () const
 Get the name of the animation. More...
 
void delayStart (Time delay)
 Play the animation after a delay. More...
 
Time getStartDelay () const
 Get the time waited before the animation is played. More...
 
bool isStartDelayed () const
 Check whether or not the animation is played after a delay. More...
 
void showTargetOnStart (bool show)
 Set whether or not the target is shown when the animation starts. More...
 
bool isTargetShownOnStart () const
 Check whether or not the target is shown when the animation starts. More...
 
void hideTargetOnCompletion (bool hide)
 Set whether or not the target is hidden when the animation completes. More...
 
bool isTargetHiddenOnCompletion () const
 Check whether or not the target is hidden when the animation completes. More...
 
void addFrames (Index startPos, unsigned int numOfFrames, FrameArrangement arrangement=FrameArrangement::Horizontal)
 Add frames from the spritesheet to the animation. More...
 
void addFrame (Index frame)
 Add an animation frame to the end of the animation. More...
 
void insertFrameAt (unsigned int index, Index frameIndex)
 Insert an animation frame within the current animation sequence. More...
 
std::optional< FramegetFirstFrame () const
 Get the first frame of the animation. More...
 
std::optional< FramegetLastFrame () const
 Get the last frame of the animation. More...
 
std::optional< FramegetFrameAt (unsigned int index) const
 Get the frame at an index. More...
 
const std::vector< Frame > & getAllFrames () const
 Get all the frames in the animation. More...
 
unsigned int getFrameCount () const
 Get the total number of frames in the animation. More...
 
Time getFrameTime () const
 Get the time spent on the current frame before switching to the next animation frame. More...
 
bool hasFrameAtIndex (unsigned int index) const
 Check if the animation has a frame at an index. More...
 
void removeFirstFrame ()
 Remove the first frame from the animation. More...
 
void removeLastFrame ()
 Remove the last frame from the animation. More...
 
void removeFrameAt (unsigned int index)
 Remove an animation frame withing the animation sequence. More...
 
void removeAll ()
 Remove all of the animation frames. More...
 
void finishOnFrame (int index)
 Set the frame the animation should finish on. More...
 
void finishOnFirstFrame ()
 Set the animation to finish on the first frame. More...
 
void finishOnLastFrame ()
 Set the animation to finish on the last frame. More...
 
unsigned int getCompletionFrameIndex () const
 Get the index of the completion frame. More...
 

Static Public Member Functions

static Animation::Ptr create (const std::string &name, const SpriteSheet &spriteSheet, Time duration=Time::Zero)
 Create a new animation object. More...
 

Detailed Description

A frame based animation.

This class defines the properties of a an animation such as playback and

The frame data is extracted from the spritesheet

This class is not meant to be instantiated directly, use the create function of the Animator class to create an animation

Definition at line 58 of file Animation.h.

Member Typedef Documentation

◆ Frame

Animation Frame.

Definition at line 60 of file Animation.h.

◆ Ptr

using ime::Animation::Ptr = std::shared_ptr<Animation>

Shared animation pointer.

Definition at line 61 of file Animation.h.

Member Enumeration Documentation

◆ Direction

The playing direction of the animation.

Enumerator
Forward 

The animation is played forwards.

Reverse 

The animation is played in reverse.

Alternate_Forward 

The animation alternates back and forth starting in the forward direction.

Alternate_Reverse 

The animation alternates back and forth starting in the reverse direction.

Definition at line 66 of file Animation.h.

Constructor & Destructor Documentation

◆ Animation()

ime::Animation::Animation ( const std::string &  name,
const SpriteSheet spriteSheet,
Time  duration = Time::Zero 
)

Construct an animation.

Parameters
nameName of the animation
spriteSheetThe spritesheet containing the animation frames
durationHow long the animation should play for

All the frame data used by the animation will be extracted from the spritesheet. As a result, the spritesheet must already be constructed before passed it as an argument. Passing an uncreated SpriteSheet is undefined behavior

By default the duration is derived from the frame rate. If the duration is specified then the frame rate will be overridden and derived from the given duration

See also
setFrameRate

Member Function Documentation

◆ addFrame()

void ime::Animation::addFrame ( Index  frame)

Add an animation frame to the end of the animation.

Parameters
frameIndex of the frame to be added from the spritesheet

◆ addFrames()

void ime::Animation::addFrames ( Index  startPos,
unsigned int  numOfFrames,
FrameArrangement  arrangement = FrameArrangement::Horizontal 
)

Add frames from the spritesheet to the animation.

Parameters
startPosPosition of the first frame on the spritesheet
numOfFramesNumber of animation frames
arrangementHow the frames are arranged on the spritesheet

◆ create()

static Animation::Ptr ime::Animation::create ( const std::string &  name,
const SpriteSheet spriteSheet,
Time  duration = Time::Zero 
)
static

Create a new animation object.

Parameters
nameName of the animation
spriteSheetFilename of the image file with the animation frames
durationHow long the animation plays before it stops or loops around
Returns
The new animation object

All the frame data used by the animation will be extracted from the spritesheet. As a result, the spritesheet must already be constructed before passed it as an argument. Passing an uncreated SpriteSheet is undefined behavior

By default the duration is derived from the frame rate. If the duration is specified then the frame rate will be overridden and derived from the given duration

◆ delayStart()

void ime::Animation::delayStart ( Time  delay)

Play the animation after a delay.

Parameters
delayThe time to wait before the animation is played

By default, the animation is not delayed

◆ finishOnFirstFrame()

void ime::Animation::finishOnFirstFrame ( )

Set the animation to finish on the first frame.

By default, the animation finishes on the last frame

See also
finishOnFrame

◆ finishOnFrame()

void ime::Animation::finishOnFrame ( int  index)

Set the frame the animation should finish on.

Parameters
indexThe index of the frame the animation should finish on

Note that index will be ignored if it is out of bounds. When set to a negative value, the animation will end on the last frame

By default, the animation finishes on the last frame

Warning
If the completion frame is not the last or the first frame then this function must be called every time a frame is removed from the sequence

◆ finishOnLastFrame()

void ime::Animation::finishOnLastFrame ( )

Set the animation to finish on the last frame.

By default, the animation finishes on the last frame

See also
finishOnFrame

◆ getAllFrames()

const std::vector<Frame>& ime::Animation::getAllFrames ( ) const

Get all the frames in the animation.

Returns
All the frames in he animation

◆ getCompletionFrameIndex()

unsigned int ime::Animation::getCompletionFrameIndex ( ) const

Get the index of the completion frame.

Returns
The index of the completion frame
See also
finishOnFrame

◆ getDirection()

Direction ime::Animation::getDirection ( ) const

Get the animations playing direction.

Returns
The animations playing direction
See also
setDirection

◆ getDuration()

Time ime::Animation::getDuration ( ) const

Get the duration of the animation.

Returns
The duration of the animation

◆ getFirstFrame()

std::optional<Frame> ime::Animation::getFirstFrame ( ) const

Get the first frame of the animation.

Returns
The first frame of the animation or an empty value if the animation has no frames
See also
addFrame and addFrames

◆ getFrameAt()

std::optional<Frame> ime::Animation::getFrameAt ( unsigned int  index) const

Get the frame at an index.

Parameters
indexThe index to get the frame of
Returns
The frame at the specified index or an empty value if the index is out of bounds

◆ getFrameCount()

unsigned int ime::Animation::getFrameCount ( ) const

Get the total number of frames in the animation.

Returns
The total number of frames in the animation

◆ getFrameRate()

unsigned int ime::Animation::getFrameRate ( ) const

Get the animations playback frame rate.

Returns
The animations playback frame rate

◆ getFrameTime()

Time ime::Animation::getFrameTime ( ) const

Get the time spent on the current frame before switching to the next animation frame.

Returns
The time spent on the current frame before changing to the next frame

◆ getLastFrame()

std::optional<Frame> ime::Animation::getLastFrame ( ) const

Get the last frame of the animation.

Returns
The last frame or an empty value if the animation has no frames
See also
addFrame and addFrames

◆ getName()

const std::string& ime::Animation::getName ( ) const

Get the name of the animation.

Returns
The name of the animation

◆ getRepeatCount()

int ime::Animation::getRepeatCount ( ) const

Get the number of times the animation is repeated before completing.

Returns
The number of times the animation is repeated

The return value of this function imply the following:

-1 = The animation repeats forever 0 = The animation does not repeat x = The animation repeats x times

See also
setRepeatCount

◆ getSpriteSheet()

const SpriteSheet& ime::Animation::getSpriteSheet ( ) const

Get the spritesheet used by the animation.

Returns
The spritesheet used by the animation

◆ getStartDelay()

Time ime::Animation::getStartDelay ( ) const

Get the time waited before the animation is played.

Returns
The start delay of the animation

◆ hasFrameAtIndex()

bool ime::Animation::hasFrameAtIndex ( unsigned int  index) const

Check if the animation has a frame at an index.

Parameters
indexIndex to be checked
Returns
True if the animation has a frame at the given index or false if the index is out of bounds

◆ hideTargetOnCompletion()

void ime::Animation::hideTargetOnCompletion ( bool  hide)

Set whether or not the target is hidden when the animation completes.

Parameters
showTrue to hide the target or false to leave the targets visibility state unmodified

By default the targets visibility state is unmodified. This means that if the target was shown when the animation completed, then it will remain shown and if the target was hidden, it will remain hidden

See also
showTargetOnStart

◆ insertFrameAt()

void ime::Animation::insertFrameAt ( unsigned int  index,
Index  frameIndex 
)

Insert an animation frame within the current animation sequence.

Parameters
frameIndexThe index of the frame to insert from the spritesheet
indexThe index where the frame should be inserted

If index is negative or higher than the current number of frames, the frame will be added at the end instead

◆ isRepeating()

bool ime::Animation::isRepeating ( ) const

Check if the animation is repeating or not.

Returns
True if the animation repeats, otherwise false

Note that a repeating animation and a looping animation are not the same

See also
setLoop and setRepeatCount

◆ isStartDelayed()

bool ime::Animation::isStartDelayed ( ) const

Check whether or not the animation is played after a delay.

Returns
True if the animation is played after a delay, otherwise false

◆ isTargetHiddenOnCompletion()

bool ime::Animation::isTargetHiddenOnCompletion ( ) const

Check whether or not the target is hidden when the animation completes.

Returns
True if the target is hidden or false if the visibility state of the target is unmodified
See also
hideTargetOnStart

◆ isTargetShownOnStart()

bool ime::Animation::isTargetShownOnStart ( ) const

Check whether or not the target is shown when the animation starts.

Returns
True if the target is shown or false if the visibility state of the target is unmodified
See also
showTargetOnStart

◆ removeAll()

void ime::Animation::removeAll ( )

Remove all of the animation frames.

◆ removeFirstFrame()

void ime::Animation::removeFirstFrame ( )

Remove the first frame from the animation.

◆ removeFrameAt()

void ime::Animation::removeFrameAt ( unsigned int  index)

Remove an animation frame withing the animation sequence.

Parameters
indexThe index of the animation frame to be removed

◆ removeLastFrame()

void ime::Animation::removeLastFrame ( )

Remove the last frame from the animation.

◆ setDirection()

void ime::Animation::setDirection ( Direction  direction)

Set the direction in which the animation should be played.

Parameters
directionThe animations direction of play

Note that if the animation is set to alternate but it is not looped or it does not repeat, it will play once like a normal forward or reverse animation (depending on the initial direction of alternation)

By default the animation is played forwards

◆ setDuration()

void ime::Animation::setDuration ( Time  duration)

Set the new duration of the animation.

Parameters
durationDuration to set

By default the duration is determined by the frame rate. When the duration is explicitly set, the frame rate is overridden and derived from the given duration. Therefore you only need to set either the frame rate or the duration

If the specified duration is less than or equal to zero then the duration will be set to the default one

See also
setFrameRate

◆ setFrameRate()

void ime::Animation::setFrameRate ( unsigned int  frameRate)

Set the frame rate playback of the animation.

Parameters
frameRateThe frame rate to set

When the frame rate is explicitly set, the duration of the animation is overridden and derived from the given frame rate. Therefore you only need to set either the duration or the frame rate. Also not that if the frame rate is less than or equal to zero then it will be set to the default frame rate

By default, the frame rate is 24 frames per second

See also
setDuration

◆ setRepeatCount()

void ime::Animation::setRepeatCount ( int  count)

Enable or disable animation repetition.

Parameters
countThe number of times to repeat the animation

Set count to -1 to repeat forever or set it to some number x, where x is the number of times to repeat the animation before it completes or set it to 0 to disable repetition if the animation is currently repeating. Note that if count is set to value that is less than zero but not '-1', then the repeat count will be set to zero meaning that the animation will not repeat

By default, the animation does not repeat (repeat count is 0), it plays once then completes

◆ showTargetOnStart()

void ime::Animation::showTargetOnStart ( bool  show)

Set whether or not the target is shown when the animation starts.

Parameters
showTrue to show the target or false to leave the targets visibility state unmodified

By default, the target is shown when the animation starts. This means that if the target was hidden prior (explicitly, or via an animation finish event) then its visible property will be set to true when the animation starts playing

hideTargetOnStart


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