我在跳XNA时出现问题
角色稍微跳了一下,但我还是可以在回来之前上去。这样的效果是它不是一个跳跃,我也向左移动,正确工作,除非玩家在空中,否则它们不起作用。
我想要发生的是马里奥式跳跃,用户向上按压并向左或向右移动直到玩家跌倒。
有人可以帮助我。
这是我的代码:(在播放器的更新中)
public void handleInput(GameTime gameTime)
{
this.Transform.MoveIncrement = Vector2.Zero;
float timeBetweenUpdates = 0.25f * gameTime.ElapsedGameTime.Milliseconds;
if (game.KeyboardManager.isKeyDown(Keys.Left))
{
this.Transform.MoveIncrement += -this.Transform.Look;
this.Transform.IsMoved = true;
}
else if (game.KeyboardManager.isKeyDown(Keys.Right))
{
this.Transform.MoveIncrement += this.Transform.Look;
this.Transform.IsMoved = true;
}
if (game.KeyboardManager.isKeyDown(Keys.Up))
{
// this.Transform.MoveIncrement = -Vector2.UnitY * timeBetweenUpdates;
this.Transform.moveBy(-Vector2.UnitY);
this.Transform.IsMoved = true;
this.hasJumped = true;
}
else if(timeBetweenUpdates > 450)
{
hasJumped = true;
}
else if (hasJumped == true)
{
this.Transform.MoveIncrement = Vector2.UnitY * timeBetweenUpdates;
this.Transform.IsMoved= true;
}
}
答案 0 :(得分:0)
你有办法告诉你的球员是否在场吗?如果你这样做,而不仅仅将其纳入你的if
陈述。
// insert your own way of telling whether or not the player is jumping
//or if he is on the ground
bool playerIsOnGround = this.YPosition = 0;
if ( isPlayerOnGround && game.KeyboardManager.isKeyDown(Keys.Up))
{