2013-12-20 259 views
0

嘿,當我的球員在跳躍的地方,我無法向左或向右移動,但當他着陸時我可以移動。我需要這在我的跳躍,使我不能移動的平臺上鍊接等..不能在左側或右側跳躍

這裏是我的代碼:

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

回答

4

你重寫你的if (hasJumped == true)塊內你以前的this.Transform.MoveIncrement分配。這意味着如果玩家既移動又跳躍,則分配他們的動作,然後用跳躍動作覆蓋它。你應該以某種方式將它們加在一起,而不是覆蓋。

+0

解決了我創建了一個方法moveBy並將moveIncrement更改爲此。我不知道我能覆蓋那個價值。非常感謝 :)。 –