我从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
}
}
任何想法?
答案 0 :(得分:0)
主循环确实在运行,你没有做任何事情。
来自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();
}