1

我从 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
         }
     }

有任何想法吗?

4

1 回答 1

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();
    }
于 2013-11-04T15:45:53.780 回答