我研究過如何在slick2d中實現基礎重力系統。這裏是我有的代碼(這是在更新功能):在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
}
這裏是問題出現的地方。當我按下向上鍵時,精靈跳躍並正常下降,但再次按下向上鍵不起作用。我原本以爲這是因爲我沒有重新設置,所以我添加了行來將它設置爲false,但是你仍然只能跳一次。 :/
謝謝!但對於閱讀此內容的人來說,它需要> =,而不是<= – Steampunkery
是的,沒有意識到您的最低價值更大。我做了適當的編輯。也請標記爲答案:) – Steve