1

大家好,我一直在关注本教程http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/到目前为止,它很好地播放了动画和一切,但现在我想要扩展它并停止连续循环,例如,当我释放 a 键时我希望他停止跳跃,但如果我按住 a 键我希望他继续跳跃,我按下 a 键使模型跳跃。到目前为止,我已经尝试过,但都没有奏效。我对如何做到这一点感到困惑,感谢您对此的任何帮助。

 private void HandleInput(GameTime gameTime)
    {
        currentGamePadState = GamePad.GetState(PlayerIndex.One);

        // Check for changing anims
        //SkinningData skinningData = model.Tag as SkinningData;
        SkinningData sd = jumper.model.Tag as SkinningData;

        if (currentGamePadState.Buttons.A == ButtonState.Pressed)
        {
            if (jumper.animationPlayer.CurrentClip.Name != "Fire")
                jumper.animationPlayer.StartClip(sd.AnimationClips["Fire"]);
        }


        if (currentGamePadState.Buttons.X == ButtonState.Pressed)
        {
            if (jumper.animationPlayer.CurrentClip.Name != "DieF")
                jumper.animationPlayer.StartClip(sd.AnimationClips["DieF"]);

        }

        //does not work
        if (currentGamePadState.Buttons.X == ButtonState.Released)
        {
            if (jumper.animationPlayer.CurrentClip.Name == "DieF")
                jumper.animationPlayer.StartClip(sd.AnimationClips["Idel"]);

        }


        if (currentGamePadState.Buttons.Y == ButtonState.Pressed)
        {
            if (jumper.animationPlayer.CurrentClip.Name != "Idel")
                jumper.animationPlayer.StartClip(sd.AnimationClips["Idle"]);
        }

        //does not work
        if (jumper.animationPlayer.CurrentTime ==    jumper.animationPlayer.CurrentClip.Duration)
        {
            //set him back to idel
            jumper.animationPlayer.StartClip(sd.AnimationClips["Idle"]);

        }

我在游戏中没有运气尝试过这些配置

        // Starts playing the entirety of the given clip
    public void StartClip(string clip, bool loop)
    {
        AnimationClip clipVal = skinningData.AnimationClips[clip];
        StartClip(clip, TimeSpan.FromSeconds(0), clipVal.Duration, loop);
    }

    // Plays a specific portion of the given clip, from one frame
    // index to another
    public void StartClip(string clip, int startFrame, int endFrame, bool loop)
    {
        AnimationClip clipVal = skinningData.AnimationClips[clip];

        StartClip(clip, clipVal.Keyframes[startFrame].Time,
            clipVal.Keyframes[endFrame].Time, loop);
    }

    // Plays a specific portion of the given clip, from one time
    // to another
    public void StartClip(string clip, TimeSpan StartTime, TimeSpan EndTime, bool loop)
    {
        CurrentClip = skinningData.AnimationClips[clip];
        currentTime = TimeSpan.FromSeconds(0);
        currentKeyframe = 0;
        Done = false;
        this.startTime = StartTime;
        this.endTime = EndTime;
        this.loop = loop;

        // Copy the bind pose to the bone transforms array to reset the animation
        skinningData.BindPose.CopyTo(BoneTransforms, 0);
    }
4

1 回答 1

2

你能不能在动画剪辑上附加一个布尔值来告诉它只播放一次,或者一个可以调用的活动变量。

于 2012-07-31T16:13:17.347 回答