Jump to content
  • Advertisement
Sign in to follow this  
riruilo

How do you implement PAUSE?

This topic is 3303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi mates! I know this seems a stupid question, but how do you implement PAUSE? This is the first time I have to do it and I just have two ideas: * My game objects (characters, general app state machine) use SDL_GetTick and a variable called m_time_state_was_transitated to create animations, so using a flag called g_paused perhaps my animations would have strange jumps. *A Another option is maybe use a delta value in my scene graph update function, that is, the leght in milliseconds of current or last frame, so when my game enters in a paused state, I pass zero to that part of my scene graph (but not to my paise manu, because it has some animations) Well, I never implemented that. I'd like to know your opinion. BTW, I'm creating a classic 2D platform game. Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
I would change what you loop through in update, without damaging animations like you say, making sure the deltas are all the same and animations paused as well. I think the complexity of your stuff working with time is what will make it hard.

You still want to update your menu system or whatever is going on outside the game simulation, so you could still update there.

Share this post


Link to post
Share on other sites
1) have your update code take as a parameter deltaTime.
2) don't call the update code at all if you are paused.
Most games use some kinda state machine to handle game mode (in menu, paused, running, watching a video, loading, restarting).
Each state having a set of update functions that are called each frame.
So, switching game modes results in no update functions being called for the other game mode, effectively pausing it.

Share this post


Link to post
Share on other sites
The gist plus or minus some relevance for your game:


while (1)
{
if ( !paused )
{
updateGame(dt);
}
updateUI(dt);
render();
}



-me

Share this post


Link to post
Share on other sites
The way I would implement it:
Don't call your engine/game loop update when paused (I assume you have separated the engine from the display). But call display whenever it needs to be updated (menu, View change etc.).
Store the time value when the pause state gets switched on, then subtract that from the time value when the pause state gets switched off. Then subtract that pause time from your delta time that you use to update your engine/game loop/physics/whatever.

Soo sloow

Share this post


Link to post
Share on other sites
Quote:
Original post by KulSeran
1) have your update code take as a parameter deltaTime.
2) don't call the update code at all if you are paused.
Most games use some kinda state machine to handle game mode (in menu, paused, running, watching a video, loading, restarting).
Each state having a set of update functions that are called each frame.
So, switching game modes results in no update functions being called for the other game mode, effectively pausing it.


I think this explains it the best, it is the most flexible in terms of not shutting out paused objects. For example, they can still respond to select events and be issued commands (baulder's gate pause), or make a selection sound, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by KulSeran
1) have your update code take as a parameter deltaTime.
2) don't call the update code at all if you are paused.
Most games use some kinda state machine to handle game mode (in menu, paused, running, watching a video, loading, restarting).
Each state having a set of update functions that are called each frame.
So, switching game modes results in no update functions being called for the other game mode, effectively pausing it.


1) No at the moment.

2) If I do that

BTW, I still did not implemented anything about pause, just researching.


@Palidine: It seems that what I am looking for, how do you calculate dt?

@szecs: Don't understand you very well, do you mean having a global variable that stores game time (but do not updating this variable when paused and use it instead of SDL_GetTicks?)

Thanks a lot for help.

Share this post


Link to post
Share on other sites
I guess you query the time somehow (SDL_GetTick?). And you calculate a deltatime, or does SDL_GetTick return a delta value? I didn't use that library yet (or any other).
If SDL_GetTick return a time value (no delta time), than simply use that and a global variable. I still program in C but I'm sure you can manage this thing.

The idea is that you calculate the delta time during the paused state. During the paused state you don't update timer.

C style, and not OOP.
//loop, that you want to pause
...

if( pause_toggled_true ) //switched on
{ pause_time_start = get_time(); //global variable
Paused=true; //global variable
}
else if( pause_toggled_false ) //switched off
{
pause_duration_time = get_time() - pause_time_start; //local variable
Paused = false;
}

if( !Paused ) // or maybe else if would be better here?
{
time=get_time(); //local variable
delta_time=time-old_time-pause_duration_time; //local variable
old_time = time; //global variable
pause_duration_time=0;

update_physics_or_whatever(delta_time);
}



I would use this if not using fixed timestep. But with fixed, it's a lot easier (at least I think). Notice that I didn't handle the keyboard events at all. I'm sure it's not polished/good at all, but you get the idea.
I think this post is even more un-understandable, then my previous one. SORRY

Share this post


Link to post
Share on other sites
Thanks.

SDL_GetTick() returns time in ms since app was launched.

I'm going to try what you said.
BTW, how I calculate delta on my first frame?

Share this post


Link to post
Share on other sites
Quote:
Original post by ricardo_ruiz_lopez
BTW, how I calculate delta on my first frame?

You could just set it to 0. I don't think anyone will notice if nothing moves in the first few milliseconds it takes for the first frame to be drawn [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!