gpt4 book ai didi

c++ - SFML - 流体屏幕更新?

转载 作者:太空宇宙 更新时间:2023-11-04 13:59:47 24 4
gpt4 key购买 nike

我从 sfml 2.1 开始,但我找不到如何让程序流畅地运行

我的意思是,该程序可以正常运行,但除非我执行某些操作,例如按下按钮或移动鼠标,否则主循环不会运行,

这是我的主循环代码的例子

     window.setFramerateLimit(30);  // set max fps to 30

while (window.isOpen())
{
// this code ignores the framerate limit and doesnt runs when an event is found
while (window.pollEvent(event))
{
// this code works fine but it wont run unless the user presses a key or moves the mouse
}
}

有什么想法吗?

最佳答案

主循环确实在运行,您没有在其中执行任何操作。

来自 2.1 的教程:

    while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}

// clear the window with black color
window.clear(sf::Color::Black);

// draw everything here...
// window.draw(...);

// end the current frame
window.display();
}

关于c++ - SFML - 流体屏幕更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19771268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com