# Using Animation Callback Functions

#### <a class="anchor" id="bkmrk-"></a>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](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_listener.html "An AnimationPlayerListener defines several hooks for the AnimationPlayer. In order to register an Ani...") allows to listen to a versatile set of animation events like:

<div class="contents" id="bkmrk-onstartantimation%2C-o"><div class="contents"><div class="textblock">- OnStartAntimation,
- OnResumeAnimation,
- OnPauseAnimation,
- OnDirectionChange,
- OnStopAnimation,
- OnFinishAnimation,
- OnPastEnd.

</div></div></div>#### <a class="anchor" id="bkmrk--0"></a>Implement AnimationPlayerListener Functions

In order to register an AnimationPlayerListener to an AnimationPlayer simply derive from [Candera::Animation::AnimationPlayerListener](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_listener.html "An AnimationPlayerListener defines several hooks for the AnimationPlayer. In order to register an Ani...") 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(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer, Candera::Int32 completedIterationsCount);
        virtual void OnStartAnimation(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer);
        virtual void OnStopAnimation(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer);
        virtual void OnFinishAnimation(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer);
        virtual void OnResumeAnimation(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer);
        virtual void OnPauseAnimation(<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_animation_player_base.html" title="AnimationPlayerBase is a base class for all AnimationPlayers that use an AnimationTimeDispatcher to c...">Candera::Animation::AnimationPlayerBase</a>* animationPlayer);

```

Use [Candera::Animation::AnimationPlayerBase::AddAnimationPlayerListener](http://dev.doc.cgistudio.at/APILINK/group___animation_base.html#ga6ff976e80e9312aa89fe5a9d6a16f033) and [Candera::Animation::AnimationPlayerBase::RemoveAnimationPlayerListener](http://dev.doc.cgistudio.at/APILINK/group___animation_base.html#gacfcf00e1b85c190893a61dbda34761ec) 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](http://dev.doc.cgistudio.at/APILINK/group___animation_base.html#ga229c09eb5a45b0ab000d4153543b3d5a), the application is notified about all started animations.

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