2013-11-04 61 views
1

我开始与SFML 2.1但我不能找到如何使程序运行流体SFML - 流体屏幕更新?

我的意思是,该方案的工作,但除非我做一些事情,比如按下按钮或移动鼠标,主循环不会运行,

这里是我的主循环代码

 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

[这是它应该工作的方式(http://sfml-dev.org/documentation/2.1/classsf_1_1Window.php#a338e996585faf82e93069858e3b531b7),该代码应该在“while(window.pollEvent(event))'循环之外添加运行”always“。 – fvu

+0

你应该阅读[tutorials](http://sfml-dev.org/tutorials/2.1/),它们对于使用SFML是必不可少的。例如, –

+0

如果我想要一个精灵向左移动,我应该怎么做? – user2953006

回答

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(); 
    } 
+0

我确实有代码,问题在于即使我调用函数window.display(),屏幕也不会更新; – user2953006

+0

@ user2953006那么你应该发布你的代码,如果你不告诉我们你的实际问题是什么,我们不能帮你。 – nvoigt

+0

确保你也调用window.clear(),如果你需要任何帮助,只需在这里发布代码片段 – Canvas