【问题标题】:xna 4.0 animation loopingxna 4.0 动画循环
【发布时间】:2012-08-01 01:13:37
【问题描述】:

大家好,我一直在这里 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);
    }

【问题讨论】:

    标签: animation loops xna-4.0


    【解决方案1】:

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

    【讨论】:

    • 你会将循环或活动变量放在游戏中的什么位置我真的不知道我尝试在 AnimationClip 类中进行循环控制,但效果与以前相同,但它只是播放动画中的一两帧然后冻结
    • 快速浏览您发布的链接,发现:// If we reached the end, loop back to the start. bool hasLooped = false; while (time >= currentClipValue.Duration) { hasLooped = true; time -= currentClipValue.Duration; } // If we've looped, reprocess the events if (hasLooped) { CheckEvents(ref time, ref lastTime); } } 它在您的动画播放器的 updateBoneTransforms 函数中
    • 是的,我注意到了这一点,但对于如何处理它还不是很清楚。我试着把它和那个注释掉,还有这个 // 如果我们到达终点,循环回到起点。 bool hasLooped = false; while (time >= currentClipValue.Duration) { hasLooped = false; //hasLooped = true;时间-= currentClipValue.Duration; } 并且动画仍然循环播放
    • 您是否尝试过在每个 if 语句的末尾附加一个 ELSE IF 来告诉它在您不按下按钮时不播放? if (currentGamePadState.Buttons.A == ButtonState.Pressed) { if (jumper.animationPlayer.CurrentClip.Name != "Fire") jumper.animationPlayer.StartClip(sd.AnimationClips["Fire"]); } 你甚至可以在 else if 中放置一个空闲的动画片段。
    • 我尝试了类似的方法,它只适用于一个动画,然后我放入另一个动画,它冻结了游戏。我一直在搞乱animationPlayer,这个接缝在一定程度上工作还没有完全测试它,但它停止了两个不同的动画
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多