【问题标题】:SFML - fluid screen update?SFML - 流体屏幕更新?
【发布时间】:2013-11-04 15:37:06
【问题描述】:

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

有什么想法吗?

【问题讨论】:

  • That's the way it's supposed to work,应该“始终”运行的代码应该添加到 while (window.pollEvent(event)) 循环之外。
  • 你真的应该阅读tutorials,它们对于使用 SFML 是必不可少的。
  • 例如,如果我想让一个精灵自己向左移动,我应该怎么做?
  • @user2953006 你应该阅读教程。这似乎不是技术问题,而是缺乏知识。

标签: c++ sfml frame-rate


【解决方案1】:

主循环确实运行了,你没有在其中做任何事情。

来自 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();
    }

【讨论】:

  • 我有代码,问题是即使我调用函数window.display()屏幕也不会更新;
  • @user2953006 那么您应该发布您的代码,如果您不向我们展示您的实际问题,我们将无法帮助您。
  • 确保您还调用了 window.clear(),如果您需要任何帮助,只需在此处使用代码 sn-ps 发布
猜你喜欢
  • 2017-06-06
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多