Using animations.

Dec 4, 2012 at 7:01 PM

Hi all,

I got this 'dude.fbx' model which will walk automatically when I  set the Content Processor to 'Model - Engine Nine'.
This is pretty nice and all, but even when I don't move the player, it will animate his nice walking loop.

How can I pause or stop the animation and only play it when I'm actually moving with the model? With moving I mean walking with WSAD or something.

-Stefan 

Developer
Dec 4, 2012 at 7:53 PM

You can do something like this: ( Where 'Dude' is the player. And 'Take 001' is the Animation Name. )

protected override void Update(float elapsedTime)
{
	var model = Parent.FindName<Model>("Dude");
	var keyboardState = Keyboard.GetState();

	if (keyboardState.IsKeyDown(Keys.Space))
	{
		var AniMation = model.Animations["Take 001"];
		if (AniMation.State == Nine.Animations.AnimationState.Playing)
		{
			AniMation.Pause();
		}
	}
	else
	{
		var AniMation = model.Animations["Take 001"];
		if (AniMation.State != Nine.Animations.AnimationState.Playing)
		{
			AniMation.Play();
		}
	}
}