【发布时间】:2016-07-07 18:25:23
【问题描述】:
我研究了如何在 slick2d 中实现一个基本的重力系统。这是我拥有的代码(在更新函数中):
if (input.isKeyDown(Input.KEY_UP)) {
spressed = true; //Has the UP key been pressed?
}
if (spressed) {
if (!sjumping) {//if so, are we already in the air?
Sub_vertical_speed = -1.0f * delta;//negative value indicates an upward movement
sjumping = true;//yes, we are in the air
}
if (sjumping) { //if we're in the air, make gravity happen
Sub_vertical_speed += 0.04f * delta;//change this value to alter gravity strength
}
Sub.y += Sub_vertical_speed;
}
if (Sub.y == Sub.bottom){//Sub.bottom is the floor of the game
sjumping = false;//we're not jumping anymore
spressed = false;//up key reset
}
这就是问题出现的地方。当我按下向上键时,精灵会正常跳跃并下降,但再次按下向上键没有任何反应。我本来以为是因为我没有reset spressed,所以我加了一行设置为false,但是你还是只能跳一次。 :/
【问题讨论】: