An animator for ime::Sprite. More...
#include <Animator.h>
Public Member Functions | |
Animator () | |
Default constructor. More... | |
Animator (Sprite &target) | |
Constructor. More... | |
Animator (const Animator &other) | |
Copy constructor. More... | |
Animator & | operator= (Animator) |
Copy assignment operator. More... | |
Animation::Ptr | createAnimation (const std::string &name, const SpriteSheet &spriteSheet, const Time &duration=Time::Zero) |
Create an animation in the animator. More... | |
void | setTarget (Sprite &target) |
Set the animation target. More... | |
void | setTimescale (float timescale) |
Set the timescale factor. More... | |
float | getTimescale () const |
Get the timescale factor. More... | |
bool | addAnimation (Animation::Ptr animation) |
Add an animation to the animator. More... | |
void | addAnimation (std::initializer_list< Animation::Ptr > animations) |
Add multiple animations at the same time to the animator. More... | |
Animation::Ptr | getAnimation (const std::string &name) const |
Get an animation in the animator. More... | |
Animation::Ptr | getActiveAnimation () const |
Get the animation that's currently playing. More... | |
AnimationFrame * | getCurrentFrame () |
Get the frame that is currently displayed by the active animation. More... | |
const AnimationFrame * | getCurrentFrame () const |
AnimationFrame * | getNextFrame () |
Get the frame that comes after the frame that is currently displayed by the active animation. More... | |
const AnimationFrame * | getNextFrame () const |
AnimationFrame * | getPreviousFrame () |
Get the frame that comes before the frame that is currently displayed by the active animation. More... | |
const AnimationFrame * | getPreviousFrame () const |
bool | removeAnimation (const std::string &name) |
Remove an animation from the animator. More... | |
void | removeAll () |
Remove all animations from the animator. More... | |
bool | hasAnimation (const Animation::Ptr &animation) const |
Check whether or not an animation exists in the animator. More... | |
bool | hasAnimation (const std::string &name) const |
Check whether or not an animation exists in the animator. More... | |
void | chainAnimation (Animation::Ptr animation) |
Chain an animation to the current animation. More... | |
void | chainAnimation (const std::string &name) |
Chain an animation to the current animation. More... | |
bool | unchain (const std::string &name) |
Unchain an animation from a the current animations chain. More... | |
void | clearAllChains () |
Remove all the animations chained to the current animation. More... | |
bool | switchAnimation (const std::string &name, bool ignorePlaying=false) |
Change the current active animation. More... | |
void | startAnimation (const std::string &name, bool unchain=false) |
Play an animation immediately. More... | |
void | play () |
Play the current animation. More... | |
void | pause () |
Pause the current animation. More... | |
void | resume () |
Resume a paused animation. More... | |
void | stop () |
Stop the current animation. More... | |
void | restart () |
Restart the current animation from the beginning. More... | |
void | complete () |
Force the current animation to complete. More... | |
bool | isAnimationPlaying () const |
Check if an animation is playing or not. More... | |
bool | isAnimationPaused () const |
Check if the animation is paused or not. More... | |
bool | isAnimationStarted () const |
Check if the current animation has started or not. More... | |
void | suspendedEventListener (int id, bool suspend) |
Prevent further executions of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (int id) |
Remove an event listener from an event. More... | |
int | onAnimStart (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation start event. More... | |
int | onAnimPlay (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation play event. More... | |
int | onAnimPause (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation pause event. More... | |
int | onAnimResume (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation resume event. More... | |
int | onAnimRestart (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation restart event. More... | |
int | onAnimStop (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation stop event. More... | |
int | onAnimRepeat (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation repeat event. More... | |
int | onAnimComplete (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation complete event. More... | |
int | onAnimSwitch (const Callback< Animation * > &callback, bool oneTime=false) |
Add an event listener to an animation switch event. More... | |
void | update (Time deltaTime) |
An animator for ime::Sprite.
An ime::Animator takes an ime::Animation object and animates an ime::Sprite with the properties of the ime::Animation.
The animator can store multiple animations but only one can be played at a time. The animator must not be instantiated directly, a ime::Sprite is bundled with its animator which can be accessed with the ime::Sprite::getAnimator function
Definition at line 46 of file Animator.h.
ime::Animator::Animator | ( | ) |
Default constructor.
|
explicit |
Constructor.
target | Sprite to be animated |
You don't have to call setTarget when this constructor is used
ime::Animator::Animator | ( | const Animator & | other | ) |
Copy constructor.
other | The animator to construct this animator from |
bool ime::Animator::addAnimation | ( | Animation::Ptr | animation | ) |
Add an animation to the animator.
animation | The animation to be added |
void ime::Animator::addAnimation | ( | std::initializer_list< Animation::Ptr > | animations | ) |
Add multiple animations at the same time to the animator.
animations | Animations to be added |
void ime::Animator::chainAnimation | ( | Animation::Ptr | animation | ) |
Chain an animation to the current animation.
animation | The animation to be chained |
A chained animation is an animation that plays immediately after, the current animation finishes. If there is no current animation then this animation will be set as the current animation and played. If the current animation is chained to another animation then then the given animation will be chained to that animation
void ime::Animator::chainAnimation | ( | const std::string & | name | ) |
Chain an animation to the current animation.
name | The name of the animation to be chained |
A chained animation is an animation that plays immediately after, the current animation finishes. If there is no current animation then this animation will be set as the current animation and played. If the current animation is chained to another animation then then the given animation will be chained to that animation
void ime::Animator::clearAllChains | ( | ) |
Remove all the animations chained to the current animation.
void ime::Animator::complete | ( | ) |
Force the current animation to complete.
Animation::Ptr ime::Animator::createAnimation | ( | const std::string & | name, |
const SpriteSheet & | spriteSheet, | ||
const Time & | duration = Time::Zero |
||
) |
Create an animation in the animator.
name | Name of the animation |
spriteSheet | The spritesheet containing the animation frames |
duration | The duration of the animation |
Animation::Ptr ime::Animator::getActiveAnimation | ( | ) | const |
Get the animation that's currently playing.
Animation::Ptr ime::Animator::getAnimation | ( | const std::string & | name | ) | const |
Get an animation in the animator.
name | The name of the animation to retrieve |
AnimationFrame * ime::Animator::getCurrentFrame | ( | ) |
Get the frame that is currently displayed by the active animation.
AnimationFrame * ime::Animator::getNextFrame | ( | ) |
Get the frame that comes after the frame that is currently displayed by the active animation.
AnimationFrame * ime::Animator::getPreviousFrame | ( | ) |
Get the frame that comes before the frame that is currently displayed by the active animation.
float ime::Animator::getTimescale | ( | ) | const |
bool ime::Animator::hasAnimation | ( | const Animation::Ptr & | animation | ) | const |
Check whether or not an animation exists in the animator.
animation | The animation to be checked |
bool ime::Animator::hasAnimation | ( | const std::string & | name | ) | const |
Check whether or not an animation exists in the animator.
name | The name of the animation to be checked |
bool ime::Animator::isAnimationPaused | ( | ) | const |
Check if the animation is paused or not.
This function returns false if there is no current animation or the animation is playing or is stopped
bool ime::Animator::isAnimationPlaying | ( | ) | const |
Check if an animation is playing or not.
This function will return false if there is no current animation or when the animation is paused or stopped
bool ime::Animator::isAnimationStarted | ( | ) | const |
Check if the current animation has started or not.
Note that when play() or startAnimation() is called, the animation may not start immediately depending on whether it has a start delay or not. Therefore, isAnimationPlaying() may return true whilst this function returns false
bool ime::Animator::isEventListenerSuspended | ( | int | id | ) | const |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
int ime::Animator::onAnimComplete | ( | const Callback< Animation * > & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to an animation complete event.
callback | The function to be executed when the current animation completes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add as many event listeners as you like to this event
Add an event listener to an animation pause event.
callback | The function to be executed when the current animation is paused |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation play event.
callback | The function to be executed when the current animation starts animating |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
This event is emitted after the start delay expires. At this point the animation starts to animate. To perform an action before the start delay executes, use onStart().
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation repeat event.
callback | The function to be executed when the current animation is repeated |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add as many event listeners as you like to this event
Add an event listener to an animation restart event.
callback | The function to be executed when the current animation is restarted |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation resume event.
callback | The function to be executed when the current animation is resumed from a paused state |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation start event.
callback | The function to be executed when the current animation starts |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
This event is emitted before the start delay timer executes. To perform an action after the start delay timer expires, use onPlay().
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation stop event.
callback | The function to be executed when the current animation is stopped from a playing or paused state |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event
Add an event listener to an animation switch event.
callback | The function to be executed when the current animation is changed (see switchAnimation()) |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
You can add as many event listeners as you like to this event
void ime::Animator::play | ( | ) |
Play the current animation.
This function will start playing the current animation if it was pending a start. If the animation is paused, you have to call resume() to play it.
This function has no effect if there is no active animation waiting to be played or when there is one but it is paused
void ime::Animator::removeAll | ( | ) |
Remove all animations from the animator.
bool ime::Animator::removeAnimation | ( | const std::string & | name | ) |
Remove an animation from the animator.
name | The name of the animation to be removed |
bool ime::Animator::removeEventListener | ( | int | id | ) |
Remove an event listener from an event.
id | The unique identification number of the event listener |
void ime::Animator::restart | ( | ) |
Restart the current animation from the beginning.
void ime::Animator::setTarget | ( | Sprite & | target | ) |
Set the animation target.
target | The target to be animated |
Note that this function does not enforce the one animator per target rule. This means that if you call this function on multiple animator instances with the same argument, then target will be animated by multiple animators at once and the result may not be what you want or expect
void ime::Animator::setTimescale | ( | float | timescale | ) |
Set the timescale factor.
timescale | The new timescale factor |
The timescale factor controls the playback speed of the current animation. For example, a timescale of 2.0f will make the animation play twice as fast, a timescale of 0.5f will make the animation play at half its normal playback speed and a timescale of 0.0f will freeze the animation. Note that if timescale is negative then the timescale will be set to 1.0f (real-time)
By default the timescale is 1.0f (real-time)
void ime::Animator::startAnimation | ( | const std::string & | name, |
bool | unchain = false |
||
) |
Play an animation immediately.
name | The name of the animation to play |
unchain | True to clear all chained animations, or false to chained pending chains to the specified animation |
This function will stop the current animation if there is any and immediately play the specified animation. If the specified animation does not exist in the animator the current animation will continue playing
Note that by default, animations that were pending to be chained to the active animation prior to this function call will be chained to the specified animation. This property can be overridden by setting the unchain argument to true
To switch the animation without playing it, use the switchAnimation() function
void ime::Animator::suspendedEventListener | ( | int | id, |
bool | suspend | ||
) |
Prevent further executions of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend or false to unsuspend |
When suspended an event listener will be ignored when the event its listening to is fired. Execution will resume once it is unsuspended
bool ime::Animator::switchAnimation | ( | const std::string & | name, |
bool | ignorePlaying = false |
||
) |
Change the current active animation.
name | The name of the new animation |
ignorePlaying | True to ignore switch if an animation is currently playing otherwise false to switch anyway |
bool ime::Animator::unchain | ( | const std::string & | name | ) |
Unchain an animation from a the current animations chain.
name | The name of the animation to be unchained |