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 dataPosition) 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 dataPosition we update our animation according to the timestamp.
YI_UNUSED(dataPosition);
}
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  RepeatMode : uint8_t {
  RepeatMode::Restart = 0,
  RepeatMode::Reverse
}
 
enum  Status : uint8_t {
  Status::NotStarted = 0,
  Status::Running,
  Status::Paused,
  Status::Ended
}
 
enum  Direction : uint8_t {
  Direction::Forward = 0,
  Direction::Reverse
}
 

Public Member Functions

 CYIAnimation ()
 
virtual ~CYIAnimation ()
 
void ChangeDirection ()
 
Direction GetDirection () const
 
uint64_t GetDuration () const
 
uint64_t GetLastDeltaTime () const
 
CYIAnimationGetNext () const
 
CYIAnimationGetPrevious () const
 
void * GetUserData () const
 
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 newSimpleDur)
 
void SetDirection (Direction direction)
 
void SetDuration (uint64_t dur)
 
void SetRepeatCount (uint64_t repeatCount)
 
void SetRepeatMode (RepeatMode repeatMode)
 
void SetStartTime (uint64_t startTime)
 
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
 
- Static Public Attributes inherited from CYITime::UpdateListener
static const uint32_t DEFAULT_UPDATE_PRIORITY = 0
 

Member Enumeration Documentation

◆ Direction

enum CYIAnimation::Direction : uint8_t
strong
Enumerator
Forward 

Plays the animation from start to end.

Reverse 

Plays the animation from end to start.

◆ RepeatMode

enum CYIAnimation::RepeatMode : uint8_t
strong
Enumerator
Restart 

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

Reverse 

The animation inverses its progression direction from the previous cycle.

◆ Status

enum CYIAnimation::Status : uint8_t
strong
Enumerator
NotStarted 

The animation is not playing.

Running 

The animation is playing.

Paused 

The animation is paused.

Ended 

The animation has finished.

Constructor & Destructor Documentation

◆ CYIAnimation()

CYIAnimation::CYIAnimation ( )

◆ ~CYIAnimation()

virtual CYIAnimation::~CYIAnimation ( )
virtual

Member Function Documentation

◆ AddListener()

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

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

See also
CYIAnimation::Listener

◆ ChangeDirection()

void CYIAnimation::ChangeDirection ( )

Reverse the current direction the animation is playing.

◆ GetDirection()

Direction CYIAnimation::GetDirection ( ) const

Returns the current animation direction.

See also
CYIAnimation::Direction

◆ GetDuration()

uint64_t CYIAnimation::GetDuration ( ) const

Returns the current animation duration (in milliseconds).

◆ GetLastDeltaTime()

uint64_t CYIAnimation::GetLastDeltaTime ( ) const

Returns the last saved delta time (in milliseconds).

◆ GetNext()

CYIAnimation* CYIAnimation::GetNext ( ) const

Returns the next animation in the list.

◆ GetPrevious()

CYIAnimation* CYIAnimation::GetPrevious ( ) const

Returns the previous animation in the list.

◆ GetStatus()

Status CYIAnimation::GetStatus ( ) const

Returns the status of the animation.

See also
CYIAnimation::Status

◆ GetTimeInterpolator()

CYITimeInterpolator* CYIAnimation::GetTimeInterpolator ( ) const

Returns the current animation interpolation function.

◆ GetUserData()

void* CYIAnimation::GetUserData ( ) const

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

◆ InsertInList()

void CYIAnimation::InsertInList ( CYIAnimation **  ppFirstAnimation)

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

◆ Pause()

void CYIAnimation::Pause ( )

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

◆ RemoveFromList()

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.

◆ RemoveListener()

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

Removes the specified listener in the list.

◆ Reset()

void CYIAnimation::Reset ( )

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

◆ ScaleDuration()

void CYIAnimation::ScaleDuration ( uint64_t  newSimpleDur)

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

◆ SetDirection()

void CYIAnimation::SetDirection ( Direction  direction)

Changes the animation to the specified direction.

See also
CYIAnimation::Direction

◆ SetDuration()

void CYIAnimation::SetDuration ( uint64_t  dur)

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.

◆ SetNext()

void CYIAnimation::SetNext ( CYIAnimation pAnimation)

Set the next animation in the chained list.

◆ SetPrevious()

void CYIAnimation::SetPrevious ( CYIAnimation pAnimation)

Set the previous animation in the chained list.

◆ SetRepeatCount()

void CYIAnimation::SetRepeatCount ( uint64_t  repeatCount)

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.

◆ SetRepeatMode()

void CYIAnimation::SetRepeatMode ( RepeatMode  repeatMode)

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

See also
RepeatMode

◆ SetStartTime()

void CYIAnimation::SetStartTime ( uint64_t  startTime)

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.

◆ SetTimeInterpolator()

void CYIAnimation::SetTimeInterpolator ( CYITimeInterpolator pTimeInterpolator)

Specify the time interpolator function The Default value is CYIInterpolateLinear.

See also
CYIInterpolateLinear.

◆ SetUserData()

void CYIAnimation::SetUserData ( void *  pPrivData)

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

See also
CYIAnimation::Listener

◆ Start()

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.

◆ Terminate()

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

◆ ANIMATION_REPEAT_COUNT_INFINITE

const uint64_t CYIAnimation::ANIMATION_REPEAT_COUNT_INFINITE
static

◆ ANIMATION_TIME_UNDEFINED

const uint64_t CYIAnimation::ANIMATION_TIME_UNDEFINED
static

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