SFML community forums
Help => General => Topic started by: Poraft on June 03, 2011, 02:46:03 pm
-
Hello,
First of all I would like to say that I'm pretty bad at english.
But anyway, the problem is I would like to pause my game, but it doesnt really works what I've now.
while(App.GetEvent(event))
{
if((event.Type == sf::Event::KeyReleased) && (event.Key.Code == sf::Key::P))
{
gamePause = true;
while(gamePause == true)
{
std::cout << "GAME PAUSED" << std::endl;
//delay before able to unpause
if(timer.GetElapsedTime() > 1)
{
if((event.Type == sf::Event::KeyReleased) && (event.Key.Code == sf::Key::P))
{
gamePause = false;
std::cout << "GAME UNPAUSED" << std::endl;
}
}
}
timer.Reset();
}
}
Please Help me, and sorry if this is posted in the wrong board :roll:
It's SFML 1.6 as you will probably notice :wink:
Thanks
-
Your "event" variable won't be updated if you don't call GetEvent in your wait loop.
-
Also, you will still want to draw things when you're paused. The only thing you don't want to do is update stuff.
A typical game loop looks like this:
while(game_running)
{
ProcessEventsAndInput();
UpdateWorld();
DrawWorld();
}
To pause it, you just stop updating:
while(game_running)
{
ProcessEventsAndInput();
if(!game_paused)
UpdateWorld();
DrawWorld();
}
-
Thanks :D