在跳跃时不能向左或向右移动

时间:2013-12-20 14:31:29

标签: c# xna

嘿,当我的球员跳到我无法向左或向右移动的位置时,我遇到了问题,但是当他降落时我可以移动。我在跳跃中需要这个,这样我就无法从平台移动到平台等......

这是我的代码:

 public void handleInput(GameTime gameTime)
        {
            this.Transform.MoveIncrement = Vector2.Zero;
            float timeBetweenUpdates = 0.25f * gameTime.ElapsedGameTime.Milliseconds;

            if (game.KeyboardManager.isKeyDown(left))
            {
                this.Transform.MoveIncrement += -this.Transform.Look * timeBetweenUpdates;
                this.Transform.IsMoved = true;
            }
            if (game.KeyboardManager.isKeyDown(right))
            {
                this.Transform.MoveIncrement += this.Transform.Look * timeBetweenUpdates;
                this.Transform.IsMoved = true;
            }
            if (game.KeyboardManager.isKeyDown(up) && hasJumped == false)
            {
                this.Transform.moveBy(-Vector2.UnitY * 400);
                this.Transform.IsMoved = true;
                hasJumped = true;
            }
            if (hasJumped == true)
            {
                this.Transform.MoveIncrement = Vector2.UnitY * timeBetweenUpdates;
                this.Transform.IsMoved = true;
                //hasJumped = false;
            }
        }

1 个答案:

答案 0 :(得分:4)

您正在覆盖this.Transform.MoveIncrement块内if (hasJumped == true)之前的{{1}}作业。这意味着如果玩家同时移动和跳跃,则分配他们的移动,然后用跳跃动作覆盖它。你应该以某种方式将它们加在一起,而不是覆盖。