-2

我不明白如何暂停 XNA 的动画。我可以“开始”我的模型的动画,但不能停止它。我使用 SkinningSample_4_0 示例 dll

这是我要使用的代码。

    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)
{
            KeyboardState key = Keyboard.GetState();
            animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
            //  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);
            }
}
4

1 回答 1

0

终于自己找到了^^

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);
}
于 2012-12-16T00:04:38.837 回答