Creating and Running the Idle Animation
- After the dwarf animator is created, we want to load an animation that was stored in the file. The ModelAnimator.Animations property contains a collection of animations loaded in from the content pipeline.
- To create a new AnimationController to run one of these animations, we just pass in the animation.
- To run the animation, enumerate through the BonePose objects stored in dwarfAnimator.BonePoses and set their CurrentController property to the desired AnimationController
- For convenience, lets create a method to run an animation on all bones:
// Add this as a new method
private void RunController(ModelAnimator animator, AnimationController controller)
{
foreach (BonePose p in animator.BonePoses)
{
p.CurrentController = controller;
p.CurrentBlendController = null;
}
}
- Ignore p.CurrentBlendController for now.
- Now lets create the idle animation and run it in the LoadGraphicsContent method:
// Add this as a member variable
AnimationController idle;
// Add this in LoadGraphicsContent
idle = new AnimationController(this,
dwarfAnimator.Animations["idle0"]);
RunController(dwarfAnimator,idle);
- Great! We have our dwarf animated! Before we move on though, lets quickly take care of some busy work and create the rest of the controllers that we will use for our tutorial:
// Add these as member variables
AnimationController walk, run, nod, crouch, stayCrouched;
// Add this in LoadGraphicsContent
run = new AnimationController(this, dwarfAnimator.Animations["run"]);
walk = new AnimationController(this, dwarfAnimator.Animations["walk"]);
crouch = new AnimationController(this, dwarfAnimator.Animations["crouchDown"]);
stayCrouched = new AnimationController(this, dwarfAnimator.Animations["stayCrouched"]);
nod = new AnimationController(this, dwarfAnimator.Animations["nodHead"]);