You.i Engine
CYIAnimation Class Reference

Detailed Description

Used to create animations programatically.

This class can be used to create an animation programatically. The animation can be played and notify listeners when it has completed.

Animations are composed of zero or more animations in a list. Each animation contains information on its own execution over time, such as the duration, and current state.

To create a new animation, classes should extend CYIAnimation::Listener, implement OnAnimate, and set this new class as a listener to a CYIAnimation instance. For instance:

class CYIAnimationListenerImplementation : public CYIAnimation::Listener
{
public:
CYIAnimationListenerImplementation()
{
//Create our animation, set the duration, and add ourselves as a listener
m_pAnimation = new CYIAnimation();
m_pAnimation->SetDuration(500);
m_pAnimation->AddListener(this);
}
virtual ~CYIAnimationListenerImplementation()
{
delete m_pAnimation;
m_pAnimation = nullptr;
}
virtual void OnAnimate(CYIAnimation *pAnimation, float fDataPosition) override
{
//A listener can be added to many different CYIAnimations.
//We want to make sure that we're only animating for the animation we created.
if (pAnimation != m_pAnimation)
{
return;
}
//Using fDataPosition we update our animation according to the timestamp.
YI_UNUSED(fDataPosition);
}
private:
CYIAnimation *m_pAnimation;
};

#include <animation/YiAnimation.h>

Inheritance diagram for CYIAnimation:

Classes

class  Listener
 Base class used to listen to one or more CYIAnimations as they update over time. More...
 

Public Types

enum  REPEAT_MODE {
  REPEAT_RESTART = 0,
  REPEAT_REVERSE
}
 
enum  STATUS {
  STATUS_NOT_STARTED = 0,
  STATUS_RUNNING,
  STATUS_PAUSED,
  STATUS_ENDED
}
 
enum  DIRECTION {
  DIRECTION_FORWARD = 0,
  DIRECTION_REVERSE
}
 

Public Member Functions

 CYIAnimation ()
 
virtual ~CYIAnimation ()
 
void ChangeDirection ()
 
CYIAnimation::DIRECTION GetDirection () const
 
uint64_t GetDuration () const
 
uint64_t GetLastDeltaTime () const
 
CYIAnimationGetNext () const
 
CYIAnimationGetPrevious () const
 
void * GetUserData () const
 
CYIAnimation::STATUS GetStatus () const
 
CYITimeInterpolatorGetTimeInterpolator () const
 
void InsertInList (CYIAnimation **ppFirstAnimation)
 
void RemoveFromList (CYIAnimation **ppFirstAnimation)
 
void Pause ()
 
void Reset ()
 
void AddListener (CYIAnimation::Listener *pListener)
 
void RemoveListener (CYIAnimation::Listener *pListener)
 
void ScaleDuration (uint64_t uNewSimpleDur)
 
void SetDirection (CYIAnimation::DIRECTION direction)
 
void SetDuration (uint64_t uDur)
 
void SetRepeatCount (uint64_t uRepeatCount)
 
void SetRepeatMode (CYIAnimation::REPEAT_MODE eRepeatMode)
 
void SetStartTime (uint64_t uStartTime)
 
void SetTimeInterpolator (CYITimeInterpolator *pTimeInterpolator)
 
void SetNext (CYIAnimation *pAnimation)
 
void SetPrevious (CYIAnimation *pAnimation)
 
void SetUserData (void *pPrivData)
 
void Start ()
 
void Terminate ()
 
- Public Member Functions inherited from CYITime::UpdateListener
 UpdateListener ()
 
virtual ~UpdateListener ()
 
virtual bool GetDisablesInput ()
 

Static Public Attributes

static const uint64_t ANIMATION_TIME_UNDEFINED
 
static const uint64_t ANIMATION_REPEAT_COUNT_INFINITE
 

Member Enumeration Documentation

Enumerator
DIRECTION_FORWARD 

Plays the animation from start to end.

DIRECTION_REVERSE 

Plays the animation from end to start.

Enumerator
REPEAT_RESTART 

The data position restarts from 0.0 and increases. (modulo the effects of the time interpolator)

REPEAT_REVERSE 

The animation inverses its progression direction from the previous cycle.

Enumerator
STATUS_NOT_STARTED 

The animation is not playing.

STATUS_RUNNING 

The animation is playing.

STATUS_PAUSED 

The animation is paused.

STATUS_ENDED 

The animation has finished.

Constructor & Destructor Documentation

CYIAnimation::CYIAnimation ( )
virtual CYIAnimation::~CYIAnimation ( )
virtual

Member Function Documentation

void CYIAnimation::AddListener ( CYIAnimation::Listener pListener)

Adds a listener for the callbacks : OnAnimate(), OnAnimationBegin() and OnAnimationEnd().

See also
CYIAnimation::Listener
void CYIAnimation::ChangeDirection ( )

Reverse the current direction the animation is playing.

CYIAnimation::DIRECTION CYIAnimation::GetDirection ( ) const

Returns the current animation direction.

See also
DIRECTION
uint64_t CYIAnimation::GetDuration ( ) const

Returns the current animation duration (in milliseconds).

uint64_t CYIAnimation::GetLastDeltaTime ( ) const

Returns the last saved delta time (in milliseconds).

CYIAnimation* CYIAnimation::GetNext ( ) const

Returns the next animation in the list.

CYIAnimation* CYIAnimation::GetPrevious ( ) const

Returns the previous animation in the list.

CYIAnimation::STATUS CYIAnimation::GetStatus ( ) const

Returns the status of the animation.

See also
STATUS
CYITimeInterpolator* CYIAnimation::GetTimeInterpolator ( ) const

Returns the current animation interpolation function.

void* CYIAnimation::GetUserData ( ) const

Returns the user data set previously. Useful for the listeners.

void CYIAnimation::InsertInList ( CYIAnimation **  ppFirstAnimation)

Inserts this animation at the beginning of the chained list whose first element pointer is provided.

void CYIAnimation::Pause ( )

Pauses the current animation. The animation can be restarted by calling Start().

void CYIAnimation::RemoveFromList ( CYIAnimation **  ppFirstAnimation)

Removes this animation from the chained list whose first element pointer is provided The animation must already be part of that list. If it is not, or is part of another list, the consequences are unpredictable.

void CYIAnimation::RemoveListener ( CYIAnimation::Listener pListener)

Removes the specified listener in the list.

void CYIAnimation::Reset ( )

Resets the animation status and start time. The animation won't automatically restart until Start() or SetStartTime() is called

void CYIAnimation::ScaleDuration ( uint64_t  uNewSimpleDur)

Assigns new duration and scales the animation accordingly. Re-assigns the animation duration to the new duration. The current animation position remains unchanged, relatively to the duration (if the current position was at 30% of the previous duration, it will still be at 30% of the new duration.)

No effect if the current repeatCount is ANIMATION_REPEAT_COUNT_INFINITE No effect if the current animation status is CYIAnimation::STATUS_ENDED

void CYIAnimation::SetDirection ( CYIAnimation::DIRECTION  direction)

Changes the animation to the specified direction.

See also
DIRECTION
void CYIAnimation::SetDuration ( uint64_t  uDur)

Sets the animation's duration. Setting to ANIMATION_TIME_UNDEFINED causes the animation to run forever but but not advance in data position Must be called before animation starts, has no effect otherwise.

void CYIAnimation::SetNext ( CYIAnimation pAnimation)

Set the next animation in the chained list.

void CYIAnimation::SetPrevious ( CYIAnimation pAnimation)

Set the previous animation in the chained list.

void CYIAnimation::SetRepeatCount ( uint64_t  uRepeatCount)

Sets the number of times the animation should play.

Default is 1.

When called with 0, the repeatCount is set to 1 instead.

Set to ANIMATION_REPEAT_COUNT_INFINITE for an indefinitely repeating animation. The animation's total active time is (repeatCount * duration).

It has no effect if the animation is running or paused.

void CYIAnimation::SetRepeatMode ( CYIAnimation::REPEAT_MODE  eRepeatMode)

Sets the behaviour of the animation when it repeats. Has no effect if the animation is running or paused.

See also
REPEAT_MODE
void CYIAnimation::SetStartTime ( uint64_t  uStartTime)

Sets the start time for the animation.

If there was already a valid start time (Start() or SetStartTime() previously called), this function has no effect. Call Reset() first if you want to specify a new start time.

void CYIAnimation::SetTimeInterpolator ( CYITimeInterpolator pTimeInterpolator)

Specify the time interpolator function The Default value is CYIInterpolateLinear.

See also
CYIInterpolateLinear.
void CYIAnimation::SetUserData ( void *  pPrivData)

Set the user data. User data will be passed through the listeners' callback functions.

See also
CYIAnimation::Listener
void CYIAnimation::Start ( )

Starts or restarts the animation immediately. If the animation is paused, it is resumed. If the animation is ended or already running, the function has no effect (call Reset() first) If a previous start time had been provided (but animation had not started yet), that start time is discarded.

void CYIAnimation::Terminate ( )

Terminates the animation by advancing to its end time, thus triggering a call to OnAnimationEnd() and leaving it in CYIAnimation::STATUS_ENDED state.

If the animation repeat count is ANIMATION_REPEAT_COUNT_INFINITE, OnAnimationEnd() is not called but the status becomes CYIAnimation::STATUS_ENDED.

If the animation is paused when this function is called, it is restarted, then advanced to its end as described above.

Member Data Documentation

const uint64_t CYIAnimation::ANIMATION_REPEAT_COUNT_INFINITE
static
const uint64_t CYIAnimation::ANIMATION_TIME_UNDEFINED
static

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