Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Pause the game  (Read 17028 times)

0 Members and 1 Guest are viewing this topic.

Poraft

  • Newbie
  • *
  • Posts: 24
    • View Profile
Pause the game
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Pause the game
« Reply #1 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.
Laurent Gomila - SFML developer

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Pause the game
« Reply #2 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();
}

Poraft

  • Newbie
  • *
  • Posts: 24
    • View Profile
Pause the game
« Reply #3 on: June 03, 2011, 06:57:14 pm »
Thanks :D