0
\$\begingroup\$

I do not understand how to pause an animation of XNA. I can "Start" the animation of my model but not stop it. I use SkinningSample_4_0 sample dll

Here is my code to use.

Here is my code to use.

 protected override void LoadContent() { //Model - Player model_player = Content.Load<Model>("Models\\Player\\models"); // Look up our custom skinning information. SkinningData skinningData = model_player.Tag as SkinningData; if (skinningData == null) throw new InvalidOperationException ("This model does not contain a SkinningData tag."); // Create an animation player, and start decoding an animation clip. animationPlayer = new AnimationPlayer(skinningData); AnimationClip clip = skinningData.AnimationClips["ArmLowAction_006"]; animationPlayer.StartClip(clip); } protected overide update(GameTime gameTime) { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); KeyboardState key = Keyboard.GetState(); // If player don't move -> stop anim if (!key.IsKeyDown(Keys.W) && !keyStateOld.IsKeyUp(Keys.S) && !keyStateOld.IsKeyUp(Keys.A) && !keyStateOld.IsKeyUp(Keys.D)) { //animation stop ? not exist ? animationPlayer.Stop(); isPlayerStop = true; } else { if(isPlayerStop == true) { isPlayerStop = false; animationPlayer.StartClip(Clip); } } 
\$\endgroup\$
5
  • \$\begingroup\$ Could it be !key.IsKeyDown(Keys.W) ? Should it be !keyStateOld.IsKeyUp(Keys.W)? \$\endgroup\$ Commented Dec 15, 2012 at 16:57
  • \$\begingroup\$ Maybe, but this is only representative. My real problem is that the stop function does not exist. And I do not know how Stope \$\endgroup\$ Commented Dec 15, 2012 at 17:23
  • \$\begingroup\$ Where is your animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); \$\endgroup\$ Commented Dec 15, 2012 at 18:02
  • \$\begingroup\$ If you want it to stop, play an idle animation or a stop animation. \$\endgroup\$ Commented Dec 15, 2012 at 18:07
  • \$\begingroup\$ I added the function animationPlayer.update (... \$\endgroup\$ Commented Dec 15, 2012 at 18:12

1 Answer 1

0
\$\begingroup\$

I have finally found myself ^^

if (!key.IsKeyDown(Keys.W) && !key.IsKeyDown(Keys.A) && !key.IsKeyDown(Keys.D) && !key.IsKeyDown(Keys.S)) { //Stop animation for player walking animationPlayer.Update(new TimeSpan(0, 0, 0), true, Matrix.Identity); } else { //Continue the animation animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } 
\$\endgroup\$
1
  • 1
    \$\begingroup\$ The first animationPlayer.Update(... is not doing anything, you can just invert the bool expresion, and only call the second animationPlayer.Update(... when the user has a key down. \$\endgroup\$ Commented Dec 16, 2012 at 18:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.