Public Member Functions | List of all members
ime::Animator Class Reference

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...
 
Animatoroperator= (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...
 
AnimationFramegetCurrentFrame ()
 Get the frame that is currently displayed by the active animation. More...
 
const AnimationFramegetCurrentFrame () const
 
AnimationFramegetNextFrame ()
 Get the frame that comes after the frame that is currently displayed by the active animation. More...
 
const AnimationFramegetNextFrame () const
 
AnimationFramegetPreviousFrame ()
 Get the frame that comes before the frame that is currently displayed by the active animation. More...
 
const AnimationFramegetPreviousFrame () 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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Animator() [1/3]

ime::Animator::Animator ( )

Default constructor.

Warning
When this constructor is used, you must call setTarget() before using the animator, otherwise undefined behavior
See also
setTarget

◆ Animator() [2/3]

ime::Animator::Animator ( Sprite target)
explicit

Constructor.

Parameters
targetSprite to be animated

You don't have to call setTarget when this constructor is used

◆ Animator() [3/3]

ime::Animator::Animator ( const Animator other)

Copy constructor.

Parameters
otherThe animator to construct this animator from
Warning
The target of other will not be copied because an animation target can only be owned by one animator. Therefore, the target to be animated will be null after construction. This means that you have to initialize the target yourself by calling the setTarget() function
See also
setTarget

Member Function Documentation

◆ addAnimation() [1/2]

bool ime::Animator::addAnimation ( Animation::Ptr  animation)

Add an animation to the animator.

Parameters
animationThe animation to be added
Returns
True if the animation was added or false if an animation with the same name as the specified animation already exists in the animator

◆ addAnimation() [2/2]

void ime::Animator::addAnimation ( std::initializer_list< Animation::Ptr animations)

Add multiple animations at the same time to the animator.

Parameters
animationsAnimations to be added
Note
If an animation with the same name as one of the animations to be added already exist in the animator, then that animation will be skipped
See also
addAnimation

◆ chainAnimation() [1/2]

void ime::Animator::chainAnimation ( Animation::Ptr  animation)

Chain an animation to the current animation.

Parameters
animationThe 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

See also
unchain

◆ chainAnimation() [2/2]

void ime::Animator::chainAnimation ( const std::string &  name)

Chain an animation to the current animation.

Parameters
nameThe 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

See also
unchain

◆ clearAllChains()

void ime::Animator::clearAllChains ( )

Remove all the animations chained to the current animation.

See also
chainAnimation and unchain

◆ complete()

void ime::Animator::complete ( )

Force the current animation to complete.

◆ createAnimation()

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

Create an animation in the animator.

Parameters
nameName of the animation
spriteSheetThe spritesheet containing the animation frames
durationThe duration of the animation
Returns
The created animation or a nullptr if an animation with the same name already exists in the animator
See also
ime::Animation::create

◆ getActiveAnimation()

Animation::Ptr ime::Animator::getActiveAnimation ( ) const

Get the animation that's currently playing.

Returns
Pointer to the active animation if there's any, otherwise a nullptr

◆ getAnimation()

Animation::Ptr ime::Animator::getAnimation ( const std::string &  name) const

Get an animation in the animator.

Parameters
nameThe name of the animation to retrieve
Returns
Pointer to the requested animation if it exists, otherwise a nullptr

◆ getCurrentFrame()

AnimationFrame * ime::Animator::getCurrentFrame ( )

Get the frame that is currently displayed by the active animation.

Returns
The current frame of the active animation or a nullptr if there is no active animation
See also
getNextFrame, getPreviousFrame

◆ getNextFrame()

AnimationFrame * ime::Animator::getNextFrame ( )

Get the frame that comes after the frame that is currently displayed by the active animation.

Returns
The next frame of the active animation or a nullptr if there is no active animation or the is no next frame
See also
getCurrentFrame, getPreviousFrame

◆ getPreviousFrame()

AnimationFrame * ime::Animator::getPreviousFrame ( )

Get the frame that comes before the frame that is currently displayed by the active animation.

Returns
The current frame of the active animation or a nullptr if there is no active animation or there is no previous frame
See also
getCurrentFrame, getNextFrame

◆ getTimescale()

float ime::Animator::getTimescale ( ) const

Get the timescale factor.

Returns
The timescale factor
See also
setTimescale

◆ hasAnimation() [1/2]

bool ime::Animator::hasAnimation ( const Animation::Ptr animation) const

Check whether or not an animation exists in the animator.

Parameters
animationThe animation to be checked
Returns
True if the animation exists, otherwise false

◆ hasAnimation() [2/2]

bool ime::Animator::hasAnimation ( const std::string &  name) const

Check whether or not an animation exists in the animator.

Parameters
nameThe name of the animation to be checked
Returns
True if the animation exists, otherwise false

◆ isAnimationPaused()

bool ime::Animator::isAnimationPaused ( ) const

Check if the animation is paused or not.

Returns
True if the animation is paused, otherwise false

This function returns false if there is no current animation or the animation is playing or is stopped

◆ isAnimationPlaying()

bool ime::Animator::isAnimationPlaying ( ) const

Check if an animation is playing or not.

Returns
True if an animation is playing, otherwise false

This function will return false if there is no current animation or when the animation is paused or stopped

◆ isAnimationStarted()

bool ime::Animator::isAnimationStarted ( ) const

Check if the current animation has started or not.

Returns
True if the animation has started, otherwise false

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

See also
play and startAnimation

◆ isEventListenerSuspended()

bool ime::Animator::isEventListenerSuspended ( int  id) const

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ onAnimComplete()

int ime::Animator::onAnimComplete ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation complete event.

Parameters
callbackThe function to be executed when the current animation completes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add as many event listeners as you like to this event

◆ onAnimPause()

int ime::Animator::onAnimPause ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation pause event.

Parameters
callbackThe function to be executed when the current animation is paused
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event

See also
onResume

◆ onAnimPlay()

int ime::Animator::onAnimPlay ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation play event.

Parameters
callbackThe function to be executed when the current animation starts animating
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

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

See also
onStart, setStartDelay

◆ onAnimRepeat()

int ime::Animator::onAnimRepeat ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation repeat event.

Parameters
callbackThe function to be executed when the current animation is repeated
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add as many event listeners as you like to this event

◆ onAnimRestart()

int ime::Animator::onAnimRestart ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation restart event.

Parameters
callbackThe function to be executed when the current animation is restarted
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event

See also
onPlay

◆ onAnimResume()

int ime::Animator::onAnimResume ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation resume event.

Parameters
callbackThe function to be executed when the current animation is resumed from a paused state
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event

See also
onPause

◆ onAnimStart()

int ime::Animator::onAnimStart ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation start event.

Parameters
callbackThe function to be executed when the current animation starts
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

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

See also
onPlay, setStartDelay

◆ onAnimStop()

int ime::Animator::onAnimStop ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation stop event.

Parameters
callbackThe function to be executed when the current animation is stopped from a playing or paused state
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

The callback is passed a pointer to the animation on invocation. You can add as many event listeners as you like to this event

See also
onPlay, onPause, onResume

◆ onAnimSwitch()

int ime::Animator::onAnimSwitch ( const Callback< Animation * > &  callback,
bool  oneTime = false 
)

Add an event listener to an animation switch event.

Parameters
callbackThe function to be executed when the current animation is changed (see switchAnimation())
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listener unique identification number

You can add as many event listeners as you like to this event

◆ operator=()

Animator & ime::Animator::operator= ( Animator  )

Copy assignment operator.

◆ pause()

void ime::Animator::pause ( )

Pause the current animation.

See also
play, resume and stop

◆ play()

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

See also
pause, resume, stop and isAnimationStarted

◆ removeAll()

void ime::Animator::removeAll ( )

Remove all animations from the animator.

◆ removeAnimation()

bool ime::Animator::removeAnimation ( const std::string &  name)

Remove an animation from the animator.

Parameters
nameThe name of the animation to be removed
Returns
True if the animation was removed or false if it does not exist in the animator

◆ removeEventListener()

bool ime::Animator::removeEventListener ( int  id)

Remove an event listener from an event.

Parameters
idThe unique identification number of the event listener
Returns
True if the event listener was removed or false if no such event listener exists

◆ restart()

void ime::Animator::restart ( )

Restart the current animation from the beginning.

◆ resume()

void ime::Animator::resume ( )

Resume a paused animation.

See also
play, pause and stop

◆ setTarget()

void ime::Animator::setTarget ( Sprite target)

Set the animation target.

Parameters
targetThe 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

◆ setTimescale()

void ime::Animator::setTimescale ( float  timescale)

Set the timescale factor.

Parameters
timescaleThe 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)

Note
The timescale of the animator is multiplied with the timescale of the current animation. For example, if the timescale of the current animation is 2.0f and the timescale of the animator is 2.0f, then the current animation will play at 4x its normal speed

By default the timescale is 1.0f (real-time)

◆ startAnimation()

void ime::Animator::startAnimation ( const std::string &  name,
bool  unchain = false 
)

Play an animation immediately.

Parameters
nameThe name of the animation to play
unchainTrue 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

See also
switchAnimation and chainAnimation

◆ stop()

void ime::Animator::stop ( )

Stop the current animation.

See also
play, pause and resume

◆ suspendedEventListener()

void ime::Animator::suspendedEventListener ( int  id,
bool  suspend 
)

Prevent further executions of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue 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

See also
isEventListenerSuspended

◆ switchAnimation()

bool ime::Animator::switchAnimation ( const std::string &  name,
bool  ignorePlaying = false 
)

Change the current active animation.

Parameters
nameThe name of the new animation
ignorePlayingTrue to ignore switch if an animation is currently playing otherwise false to switch anyway
Returns
True if the animation was switched, of false if it does not exist in the animator
Note
This function does not start the animation, it only sets the current active animation to the specified animation such that when play() is called, the given animation is played. To switch and immediately play an animation use the startAnimation() function
See also
startAnimation

◆ unchain()

bool ime::Animator::unchain ( const std::string &  name)

Unchain an animation from a the current animations chain.

Parameters
nameThe name of the animation to be unchained
Returns
True if the animation was unchained or false if the animation is not part of the current animations chain
See also
chainAnimation

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