Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
            }
}
share|improve this question
    
Could it be !key.IsKeyDown(Keys.W) ? Should it be !keyStateOld.IsKeyUp(Keys.W)? –  Luis Estrada Dec 15 '12 at 16:57
    
Maybe, but this is only representative. My real problem is that the stop function does not exist. And I do not know how Stope –  Mehdi Bugnard Dec 15 '12 at 17:23
    
Where is your animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); –  Luis Estrada Dec 15 '12 at 18:02
    
If you want it to stop, play an idle animation or a stop animation. –  Luis Estrada Dec 15 '12 at 18:07
    
I added the function animationPlayer.update (... –  Mehdi Bugnard Dec 15 '12 at 18:12

1 Answer 1

up vote 0 down vote accepted

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);
}
share|improve this answer
1  
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. –  Luis Estrada Dec 16 '12 at 18:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.