2013-11-04 58 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