List of all members | Public Types | Public Member Functions
thor::Animator< Animated, Id > Class Template Reference

Class that stores the progress of an object's animation. More...

Public Types

typedef std::function< void(Animated &, float)> AnimationFunction
 Functor to animate the objects. More...
 

Public Member Functions

 Animator ()
 Default constructor.
 
 Animator (const Animator &origin)
 Copy constructor.
 
Animatoroperator= (const Animator &origin)
 Copy assignment operator.
 
 Animator (Animator &&source)
 Move constructor.
 
Animatoroperator= (Animator &&source)
 Move assignment operator.
 
 ~Animator ()
 Destructor.
 
void addAnimation (const Id &id, const AnimationFunction &animation, sf::Time duration)
 Registers an animation with a given name. More...
 
void playAnimation (const Id &id, bool loop=false)
 Plays the animation with the given name. More...
 
void stopAnimation ()
 Interrupts the animation that is currently active. More...
 
bool isPlayingAnimation () const
 Checks whether an animation is currently playing. More...
 
Id getPlayingAnimation () const
 Returns the ID of the currently playing animation. More...
 
void update (sf::Time dt)
 Updates the animator's progress. You should call this method each frame. More...
 
void animate (Animated &animated) const
 Applies the stored animations to an object. More...
 

Detailed Description

template<class Animated, typename Id>
class thor::Animator< Animated, Id >

Class that stores the progress of an object's animation.

The Animator class takes care of multiple animations which are registered by a ID. The animations can be played at any time. Animator updates their progress and applies it to animated objects.

Member Typedef Documentation

template<class Animated , typename Id >
typedef std::function<void(Animated&, float)> thor::Animator< Animated, Id >::AnimationFunction

Functor to animate the objects.

Signature: void (Animated& animated, float progress)

  • animated is the object being animated.
  • progress is a number in [0,1] determining the animation state.

Member Function Documentation

template<class Animated , typename Id >
void thor::Animator< Animated, Id >::addAnimation ( const Id &  id,
const AnimationFunction animation,
sf::Time  duration 
)

Registers an animation with a given name.

Parameters
idValue that identifies the animation (must not be registered yet).
animationAnimation to add to the animator. The animation is copied; if you want to insert a reference instead, use the function refAnimation().
durationDuration of the animation.
template<class Animated , typename Id >
void thor::Animator< Animated, Id >::animate ( Animated &  animated) const

Applies the stored animations to an object.

Parameters
animatedObject which is animated by the current animation. If no animation is active, the object is left unchanged.
template<class Animated , typename Id >
Id thor::Animator< Animated, Id >::getPlayingAnimation ( ) const

Returns the ID of the currently playing animation.

Warning
The behavior is undefined if no animation is playing. Therefore, you have to make sure by a preceding call to isPlayingAnimation() whether it is safe to call getPlayingAnimation().
template<class Animated , typename Id >
bool thor::Animator< Animated, Id >::isPlayingAnimation ( ) const

Checks whether an animation is currently playing.

Returns
true after an animation has been started with playAnimation(), as long as it has not ended. If no animation is playing, false is returned.
template<class Animated , typename Id >
void thor::Animator< Animated, Id >::playAnimation ( const Id &  id,
bool  loop = false 
)

Plays the animation with the given name.

Parameters
idValue that identifies the animation (must already be registered).
loopTrue if the animation is played repeatedly.
template<class Animated , typename Id >
void thor::Animator< Animated, Id >::stopAnimation ( )

Interrupts the animation that is currently active.

The animated object remains in the state of the stopped animation. After this call, isPlayingAnimation() returns false.

template<class Animated , typename Id >
void thor::Animator< Animated, Id >::update ( sf::Time  dt)

Updates the animator's progress. You should call this method each frame.

Parameters
dtFrame time.

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