我跳下后不能向左或向右移动

时间:2013-12-30 20:12:25

标签: c# xna

我的问题是在我跳到平台或地板上之后,我无法向左或向右移动。然而,我仍然可以跳。

以下是我使用的代码:

 public void handleInput(GameTime gameTime)
        {
            this.Transform.MoveIncrement = Vector2.Zero;
            float timeBetweenUpdates = 0.25f * gameTime.ElapsedGameTime.Milliseconds;
            bPause = true;
            if (game.KeyboardManager.isKeyDown(left))
            {
                bPause = false;
                if(playerID == 1)
                {
                this.Presentation.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                else if(playerID == 2)
                {
                    this.Presentation.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                this.Transform.MoveIncrement += -this.Transform.Look * timeBetweenUpdates;
                this.Transform.IsMoved = true;
            }
            if (game.KeyboardManager.isKeyDown(right))
            {
                bPause = false;
                if (playerID == 1)
                {
                    this.Presentation.SpriteEffects = SpriteEffects.None;
                }
                else if(playerID == 2)
                {
                    this.Presentation.SpriteEffects = SpriteEffects.None;
                }
                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;
                game.SoundManager.getEffectInstance("JumpSound").Play();
            }
            if (hasJumped == true)
            {
                this.Transform.moveBy(Vector2.UnitY * timeBetweenUpdates);
                this.Transform.IsMoved = true;
            }
        }

这是我的球员更新(如何让我的球员移动。

 PlayerSprite pSprite = (PlayerSprite)collider;
            if((collidee is FloorSprite) && (collider is PlayerSprite ))
            {
                pSprite.hasJumped = false;
            }
            if ((collidee is WallSprite) && (collider is PlayerSprite))
            {
                WallSprite wallSprite = (WallSprite)collidee;
                PlayerSprite playerSprite = (PlayerSprite)collider;

            }
            if ((collidee is PlatformSprite) && (collider is PlayerSprite))
            {
                pSprite.hasJumped = false;
            }

这就是我告诉玩家是否已经跳过并落在某事上的方式。

1 个答案:

答案 0 :(得分:0)

if (game.KeyboardManager.isKeyDown(left))
            {
                Console.WriteLine("test");
                bPause = false;
                if(playerID == 1)
                {
                this.Presentation.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                else if(playerID == 2)
                {
                    this.Presentation.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                this.Transform.MoveIncrement += -this.Transform.Look * timeBetweenUpdates;
                Console.WriteLine((-this.Transform.Look * timeBetweenUpdates));
                this.Transform.IsMoved = true;
            }

试试这个,并告诉我你是否可以看到'test'以及'-this.Transform.Look * timeBetweenUpdates;'的价值是什么?