As always, we are going to use the code from the previous chapter, and for once we don't need to delete anything:
For our animation, we need to add new member variables in the
FrameListener
. Add a pointer holding the entity we want to animate and a pointer to the used animation state:Ogre::Entity* _ent; Ogre::AnimationState* _aniState;
Then change the constructor of the
FrameListener
to get the entity pointer as a new parameter:Example34FrameListener(Ogre::SceneNode* node,Ogre::Entity* ent,RenderWindow* win,Ogre::Camera* cam)
In the function body of the constructor, assign the given entity pointer to the new member variable:
_ent = ent;
After this, retrieve the animation state called
Dance
from the entity and store it in the member variable we created for this purpose. Finally, set the animation to be enabled and loop it:_aniState = _ent->getAnimationState("Dance"); _aniState->setEnabled(true); _aniState->setLoop(true);
Next, we need to tell the...