-2
當我按下跳躍按鈕時,如何阻止我的精靈突然在空中晃動?如何阻止我的精靈在SFML中空中顛簸?
我的代碼:
sf::Vector2f velocity, position;
const float speed,gravity,jumpSpeed;
bool groundCollision,jumping;
if (!groundCollision) {
isJumping = true;
velocity.y += gravity;
} else {
isJumping = false;
}
if (!isJumping && sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
velocity.y -= jumpSpeed;
}
我希望我的精靈跳起來下來順利當我按下跳躍現在突然顛簸起來,但回來下來順利。
請提供[mcve]。否則幾乎不可能分辨出什麼是錯的。 – nvoigt