SFML community forums
Help => General => Topic started by: LGV on August 29, 2009, 04:14:29 am
-
Hi, I have a problem that it's driving me crazy and I can't figure out how to avoid it. I was trying to this (App is a sf::RenderWindow, like in the tutorial "Using rendering windows")
while(App.IsOpened())
{
for(;;)
{
if(App.GetInput().IsKeyDown(sf::Key::Escape) break;
App.Clear(sf::Color(192, 192, 192));
}
// LOTS OF USEFUL CODE...
}
Well, this simple code, just doesn't work. I get no grey window (RGB 192,192,192 is grey), I can't get input so I can't "break" the loop. Worse, my entire machine gets really lag and almost lock up (!!). I just can't understand what I'm doing wrong. Any suggestions? I'm developing under Windows XP SP3 with Visual Studio 2008.
P.S: I was trying to do that because I'm doing a very simple menu for my game, so I need to get the game started when the user click on a button (I've already implemented this stuff and it works ok), but, until that, I have to show a menu or a picture so that is why I'm using a for( ;; ).
-
for( ;; ) is your problem IMO.
There is no Display in this loop.
-
A call to App.Display is required to get things displayed on screen.
A call to App.GetEvent is required to get sf::Input updated.
Conclusion: never create nested endless loops into your main loop, so that you don't break the main execution flow. Keep a unique skeleton and adapt what is updated / displayed using the current state of the application.
-
So after all the troubles were caused by my ugly endless loop :oops: :lol:. I'll try to do what you said Laurent, thx!!
EDIT: I did it!! I did it!! Now I've a nice menu without an ugly and dirty endless loop 8). Thx!