我如何才能阻止我的精灵在SFML中在空中颠簸
How can I stop my sprite from jolting up in air in SFML?
当我按下jump时,我如何才能阻止我的精灵突然在空中颠簸?
我的代码:
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;
}
我希望我的精灵在按下jump时能平稳地上下跳跃,现在它突然向上摇晃,但又平稳地回来了。
在这部分中,你不应该使用重力而不是跳跃速度吗?
if (!isJumping && sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
//velocity.y -= jumpSpeed * deltaTime.asSeconds();
// ^ should this jumpSpeed be gravity?
velocity.y = jumpSpeed;
velocity.y -= gravity * deltaTime.asSeconds();
}
相关文章:
- 从精灵表在 sfml 中为精灵制作动画
- 如何在精灵表上的两个不同部分之间来回切换,同时用户仍使用 SFML 持有密钥
- 如何在 SFML 上添加更多精灵?
- 为什么该代码不绘制精灵C++ SFML
- SFML无法正确移动精灵
- C++ SFML 精灵运动无法按预期工作
- SFML:在旋转SFML的精灵时,如何解决精灵质量下降
- SFML/C++ 闪烁命中效果 sf::精灵
- 试图用SFML中的精灵和纹理产生继承
- C SFML精灵不显示/工作
- 精灵不在SFML中移动
- SFML将精灵放在中心
- 如何获得精灵的实际位置并将其打印在C 和SFML中
- C++/SFML显示小精灵成员被鼠标点击更改的小故障
- C++SFML精灵大小错误
- 如何在 c++/sfml 2.1 中使任何精灵消失
- 我们可以在 SFML/C++ 中制作一个精灵数组吗?
- 我们可以在 SFML 2.1/C++ 中制作精灵的数组或多维数组吗?
- 随着时间的推移,每几秒钟喷一次精灵SFML C++
- 如何从列表中随机定位push_back()的精灵-SFML