Skip to main content
 首页 » 编程设计

c#之让我的 XNA Sprite 正确跳跃

2024年02月20日13jpfss

我一直很难让我的 sprite 跳跃。到目前为止,我有一段代码,只需轻按一下“W”,就会以恒定的速度向上发送 Sprite 。我需要能够让我的 Sprite 在开始跳跃后的某个时间或高度回到地面。 Sprite 上还有一个恒定的速度 2 来模拟某种重力。

// Walking = true when there is collision detected between the sprite and ground 
 
if (Walking == true) 
    if (keystate.IsKeyDown(Keys.W)) 
        { 
            Jumping = true; 
        } 
 
if (Jumping == true) 
    { 
        spritePosition.Y -= 10; 
    } 

任何想法和帮助将不胜感激,但如果可能的话,我更希望发布我的代码的修改版本。

请您参考如下方法:

你需要对你的 Sprite 施加一个冲动,而不是像你正在做的那样以 10 的恒定速度。 有教程不错here对于你正在尝试做的事情。