xna 4.0动画循环

时间:2012-07-31 15:27:52

标签: animation loops xna-4.0

大家好,我一直在这里遵循这个教程http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/,到目前为止它很棒的动画播放和一切,但现在我想扩展它并停止连续循环说例如我按一个键来当我释放一把钥匙时让模特跳,我希望他停止跳跃,但如果我握住一把钥匙,我希望他继续跳跃。这是我到目前为止所尝试的 并没有一个工作。 关于如何做到这一点,我感到很难过,感谢您对此的任何帮助。

 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);
    }

1 个答案:

答案 0 :(得分:2)

您是否可以在动画片段上附加bool以告诉它只播放一次,或者可以调用活动变量。