我正在制作我的第一个XNA 2D游戏,但是遇到了一些问题。 如果我跳跃,我的角色会跳起来但却不会掉下来。 另外还有一个问题是,用户可以按住空格键跳得很高,我不知道如何阻止他这么做。这是我的代码:
跳跃部分: if (FaKeyboard.IsKeyDown(Keys.Space))
{
Jumping = true;
xPosition -= new Vector2(0, 5);
}
if (xPosition.Y >= 10)
{
Jumping = false;
Grounded = false;
}
真正简单的基本引力:
if (!Grounded && !Jumping)
{
xPosition += new Vector2(1, 3) * speed;
}
这里是通过碰撞将接地设置为True或False的位置
Rectangle MegamanRectangle = new Rectangle((int)xPosition.X, (int)xPosition.Y, FrameSizeDraw.X, FrameSizeDraw.Y);
Rectangle Block1Rectangle = new Rectangle((int)0, (int)73, Block1.Width, Block1.Height);
Rectangle Block2Rectangle = new Rectangle((int)500, (int)73, Block2.Width, Block2.Height);
if ((MegamanRectangle.Intersects(Block1Rectangle) || (MegamanRectangle.Intersects(Block2Rectangle))))
{
Grounded = true;
}
else
{
Grounded = false;
}
已测试并正常工作的是grounded bool(接地布尔)和gravity(重力)。有什么想法吗?提前感谢,如果需要代码的其他部分,请随时询问。