SFML community forums

Help => General => Topic started by: Poraft on June 03, 2011, 02:46:03 pm

Title: Pause the game
Post 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.

Code: [Select]

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
Title: Pause the game
Post by: Laurent on June 03, 2011, 02:50:45 pm
Your "event" variable won't be updated if you don't call GetEvent in your wait loop.
Title: Pause the game
Post by: Disch on June 03, 2011, 04:18:04 pm
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:

Code: [Select]

while(game_running)
{
  ProcessEventsAndInput();

  UpdateWorld();

  DrawWorld();
}


To pause it, you just stop updating:

Code: [Select]

while(game_running)
{
  ProcessEventsAndInput();

  if(!game_paused)
    UpdateWorld();

  DrawWorld();
}
Title: Pause the game
Post by: Poraft on June 03, 2011, 06:57:14 pm
Thanks :D