Skip to main content

Using Animation Callback Functions

Animation Event Listener

If an application shall be notified about events of the triggered animation, a listener needs to be implemented. The class Candera::Animation::AnimationPlayerListener allows to listen to a versatile set of animation events like:

    OnStartAntimation, OnResumeAnimation, OnPauseAnimation, OnDirectionChange, OnStopAnimation, OnFinishAnimation, OnPastEnd.

    Implement AnimationPlayerListener Functions

    In order to register an AnimationPlayerListener to an AnimationPlayer simply derive from Candera::Animation::AnimationPlayerListener and override pure virtual functions with custom code.

    In the example below the 3D application derives from AnimationPlayerListener and overrides the listener's functions.

    class AnimationPlayerWidget : public CgiWidget3D, public Candera::Animation::AnimationPlayerListener
    
    
            virtual void OnPastEnd(Candera::Animation::AnimationPlayerBase* animationPlayer, Candera::Int32 completedIterationsCount);
            virtual void OnStartAnimation(Candera::Animation::AnimationPlayerBase* animationPlayer);
            virtual void OnStopAnimation(Candera::Animation::AnimationPlayerBase* animationPlayer);
            virtual void OnFinishAnimation(Candera::Animation::AnimationPlayerBase* animationPlayer);
            virtual void OnResumeAnimation(Candera::Animation::AnimationPlayerBase* animationPlayer);
            virtual void OnPauseAnimation(Candera::Animation::AnimationPlayerBase* animationPlayer);
    
    

    Use Candera::Animation::AnimationPlayerBase::AddAnimationPlayerListener and Candera::Animation::AnimationPlayerBase::RemoveAnimationPlayerListener for registering or removing a listener.

            static_cast<void>(m_animPlayer->AddAnimationPlayerListener(this));
    
    
            static_cast<void>(m_animPlayer->RemoveAnimationPlayerListener(this));
    
    

    Now the application is notified about all animation listener events it has implemented. For example when implementing the Candera::Animation::AnimationPlayerListener::OnStartAnimation, the application is notified about all started animations.

    void AnimationPlayerWidget::OnStartAnimation(Animation::AnimationPlayerBase* /* animationPlayer */)
    {
        // do something when an animation has started
    }