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 SpriteSheet & | getSpriteSheet () 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< Frame > | getFirstFrame () const |
Get the first frame of the animation. More... | |
std::optional< Frame > | getLastFrame () const |
Get the last frame of the animation. More... | |
std::optional< Frame > | getFrameAt (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... | |
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.
using ime::Animation::Frame = UIntRect |
Animation Frame.
Definition at line 60 of file Animation.h.
using ime::Animation::Ptr = std::shared_ptr<Animation> |
Shared animation pointer.
Definition at line 61 of file Animation.h.
|
strong |
The playing direction of the animation.
Definition at line 66 of file Animation.h.
ime::Animation::Animation | ( | const std::string & | name, |
const SpriteSheet & | spriteSheet, | ||
Time | duration = Time::Zero |
||
) |
Construct an animation.
name | Name of the animation |
spriteSheet | The spritesheet containing the animation frames |
duration | How 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
void ime::Animation::addFrame | ( | Index | frame | ) |
Add an animation frame to the end of the animation.
frame | Index of the frame to be added from the spritesheet |
void ime::Animation::addFrames | ( | Index | startPos, |
unsigned int | numOfFrames, | ||
FrameArrangement | arrangement = FrameArrangement::Horizontal |
||
) |
Add frames from the spritesheet to the animation.
startPos | Position of the first frame on the spritesheet |
numOfFrames | Number of animation frames |
arrangement | How the frames are arranged on the spritesheet |
|
static |
Create a new animation object.
name | Name of the animation |
spriteSheet | Filename of the image file with the animation frames |
duration | How long the animation plays before it stops or loops around |
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
void ime::Animation::delayStart | ( | Time | delay | ) |
Play the animation after a delay.
delay | The time to wait before the animation is played |
By default, the animation is not delayed
void ime::Animation::finishOnFirstFrame | ( | ) |
Set the animation to finish on the first frame.
By default, the animation finishes on the last frame
void ime::Animation::finishOnFrame | ( | int | index | ) |
Set the frame the animation should finish on.
index | The 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
void ime::Animation::finishOnLastFrame | ( | ) |
Set the animation to finish on the last frame.
By default, the animation finishes on the last frame
const std::vector<Frame>& ime::Animation::getAllFrames | ( | ) | const |
Get all the frames in the animation.
unsigned int ime::Animation::getCompletionFrameIndex | ( | ) | const |
Get the index of the completion frame.
Direction ime::Animation::getDirection | ( | ) | const |
Time ime::Animation::getDuration | ( | ) | const |
Get the duration of the animation.
std::optional<Frame> ime::Animation::getFirstFrame | ( | ) | const |
std::optional<Frame> ime::Animation::getFrameAt | ( | unsigned int | index | ) | const |
Get the frame at an index.
index | The index to get the frame of |
unsigned int ime::Animation::getFrameCount | ( | ) | const |
Get the total number of frames in the animation.
unsigned int ime::Animation::getFrameRate | ( | ) | const |
Get the animations playback frame rate.
Time ime::Animation::getFrameTime | ( | ) | const |
Get the time spent on the current frame before switching to the next animation frame.
std::optional<Frame> ime::Animation::getLastFrame | ( | ) | const |
const std::string& ime::Animation::getName | ( | ) | const |
Get the name of the animation.
int ime::Animation::getRepeatCount | ( | ) | const |
Get the number of times the animation is repeated before completing.
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
const SpriteSheet& ime::Animation::getSpriteSheet | ( | ) | const |
Get the spritesheet used by the animation.
Time ime::Animation::getStartDelay | ( | ) | const |
Get the time waited before the animation is played.
bool ime::Animation::hasFrameAtIndex | ( | unsigned int | index | ) | const |
Check if the animation has a frame at an index.
index | Index to be checked |
void ime::Animation::hideTargetOnCompletion | ( | bool | hide | ) |
Set whether or not the target is hidden when the animation completes.
show | True 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
void ime::Animation::insertFrameAt | ( | unsigned int | index, |
Index | frameIndex | ||
) |
Insert an animation frame within the current animation sequence.
frameIndex | The index of the frame to insert from the spritesheet |
index | The 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
bool ime::Animation::isRepeating | ( | ) | const |
Check if the animation is repeating or not.
Note that a repeating animation and a looping animation are not the same
bool ime::Animation::isStartDelayed | ( | ) | const |
Check whether or not the animation is played after a delay.
bool ime::Animation::isTargetHiddenOnCompletion | ( | ) | const |
Check whether or not the target is hidden when the animation completes.
bool ime::Animation::isTargetShownOnStart | ( | ) | const |
Check whether or not the target is shown when the animation starts.
void ime::Animation::removeAll | ( | ) |
Remove all of the animation frames.
void ime::Animation::removeFirstFrame | ( | ) |
Remove the first frame from the animation.
void ime::Animation::removeFrameAt | ( | unsigned int | index | ) |
Remove an animation frame withing the animation sequence.
index | The index of the animation frame to be removed |
void ime::Animation::removeLastFrame | ( | ) |
Remove the last frame from the animation.
void ime::Animation::setDirection | ( | Direction | direction | ) |
Set the direction in which the animation should be played.
direction | The 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
void ime::Animation::setDuration | ( | Time | duration | ) |
Set the new duration of the animation.
duration | Duration 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
void ime::Animation::setFrameRate | ( | unsigned int | frameRate | ) |
Set the frame rate playback of the animation.
frameRate | The 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
void ime::Animation::setRepeatCount | ( | int | count | ) |
Enable or disable animation repetition.
count | The 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
void ime::Animation::showTargetOnStart | ( | bool | show | ) |
Set whether or not the target is shown when the animation starts.
show | True 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