Animation xna 4.0动画循环

Animation xna 4.0动画循环,animation,loops,xna-4.0,Animation,Loops,Xna 4.0,大家好,我一直在关注这个教程,到目前为止,它非常棒,播放了动画和所有内容,但现在我想扩展它并停止连续循环,比如说,当我释放a键时,我按下a键使模型跳跃,我希望他停止跳跃,但如果我按住a键,我希望他继续跳跃。这是我迄今为止所尝试的 但这一切都不管用。 我在这里被难住了怎么做,谢谢你在这方面的帮助 private void HandleInput(GameTime gameTime) { currentGamePadState = GamePad.GetState(Play

大家好,我一直在关注这个教程,到目前为止,它非常棒,播放了动画和所有内容,但现在我想扩展它并停止连续循环,比如说,当我释放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);
    }

您不能在动画剪辑上附加bool以告诉它仅播放一次,或者不能调用活动变量

你会在游戏中把循环或活动变量放在哪里我真的不知道我尝试在AnimationClip类中进行循环控制,但效果与以前不同,但它只播放了动画中的一到两帧,然后FrezeLocking快速查看你发布的链接,发现:
//如果我们到达终点,循环回到起点。bool hasLooped=false;while(time>=currentClipValue.Duration){hasLooped=true;time-=currentClipValue.Duration;}//如果我们已经循环,如果(hasLooped){CheckEvents(ref-time,ref-lastTime)重新处理事件}
在你的AnimationPlayes的UpdateBonetTransforms函数中,我注意到了这一点,但对于如何处理它却一无所知。我试着把它注释出来,还有这个//如果我们到达了终点,就回到起点。bool hasLooped=false;while(time>=currentClipValue.Duration){hasLooped=false;//hasLooped=true;time-=currentClipValue.Duration;}动画仍然循环,你是否尝试在每个IF语句的末尾附加一个ELSE IF,告诉它如果你没有按下按钮,就不要播放<代码>如果(currentGamePadState.Buttons.A==ButtonState.Pressed){if(jumper.animationPlayer.CurrentClip.Name!=“Fire”)jumper.animationPlayer.StartClip(sd.AnimationClips[“Fire”]);}你甚至可以在else if中放入一个空闲的动画片段。我尝试了类似的方法,只对一个动画有效,然后我放入另一个动画,它冻结了游戏。我一直在搞乱animationPlayer,这将工作到一定程度,但它没有完全测试,但它停止了两个不同的动画