C++和SFML-通过十进制转换导致伪影
我正在使用C ++和SFML进行游戏。我在游戏中有Delta时间通过将其设置为clock.restart()。asseconds(),然后将其乘以移动偏移量。唯一的问题是,当最终移动值不是整数(或.0F)时,它会导致我的精灵之间的构造。我有一个彼此相邻的精灵网格。当我以整数偏移偏移时,它看起来不错。但是,当用小数点移动时,我可以看到精灵之间的奇怪界线。有什么方法可以解决此问题吗?
注意:我不想绕过Deltatime *偏移值,因为当FPS太高时,它将被舍入到0,并且玩家根本不会移动。
增量时间代码:
void Game::run()
{
init();
Gui::init();
Gui::mainMenu();
sf::Clock deltaClock;
while (window.isOpen())
{
sf::Event loopEvent;
while (window.pollEvent(loopEvent))
{
switch (loopEvent.type)
{
case sf::Event::Closed:
saveGame();
window.close();
break;
case sf::Event::KeyPressed:
if (loopEvent.key.code == Gui::keybinds[Action::EXIT_MENU] && Player::hasSpawned)
{
Gui::inMenu = false;
Gui::currentGameState = GameState::SETTINGS;
}
}
}
deltaTime = deltaClock.restart().asSeconds();
update();
window.setView(camera);
window.clear(sf::Color::White);
draw();
window.display();
Gui::checkGameState();
}
}
const float Game::MAKE_DELTA(const float OFFSET)
{
return OFFSET * deltaTime;
}
使用整数偏移量(或者当我绕过Make_delta()的返回值时):
带有小数偏移(从make_delta())移动(从make_delta()):
I’m making a game with C++ and SFML. I have delta time in my game by setting it to clock.restart().asSeconds() and then multiplying that by a movement offset. The only issue is that when the final movement value is not an integer (or .0f), it causes rendering artifacts between my sprites. I have a grid of sprites that are all lined up next to each other. When I move by an integer offset, it looks good. However, when moving with a decimal, I can see strange lines between the sprites. Is there any way of fixing this?
note: I don't want to round the deltatime * offset value because when fps is too high, it will be rounded to 0 and the player will not move at all.
delta time code:
void Game::run()
{
init();
Gui::init();
Gui::mainMenu();
sf::Clock deltaClock;
while (window.isOpen())
{
sf::Event loopEvent;
while (window.pollEvent(loopEvent))
{
switch (loopEvent.type)
{
case sf::Event::Closed:
saveGame();
window.close();
break;
case sf::Event::KeyPressed:
if (loopEvent.key.code == Gui::keybinds[Action::EXIT_MENU] && Player::hasSpawned)
{
Gui::inMenu = false;
Gui::currentGameState = GameState::SETTINGS;
}
}
}
deltaTime = deltaClock.restart().asSeconds();
update();
window.setView(camera);
window.clear(sf::Color::White);
draw();
window.display();
Gui::checkGameState();
}
}
const float Game::MAKE_DELTA(const float OFFSET)
{
return OFFSET * deltaTime;
}
Moving with integer offset (or when I round the return value of MAKE_DELTA()):
Moving with decimal offset (unrounded return value from MAKE_DELTA()):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论