Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Game Pausing

This topic is 7131 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

I have sort of a strange problem with game pausing. My 2D sprite movement is based on timing, and when I pause the game between levels (I use the Sleep function), the timing becomes somewhat corrupted for a few seconds. The problem is that after a pause occurs, any visible sprites that are moving on the screen start to jump around and then go back to normal movement after a second or so. I would like to know what are the better ways to correct or avoid faulty timing when you base your sprite movement on time. Perhaps by dropping frames or try to pause the game without actually stopping the game loop? The problem I see with dropping frames is that my game logic (movement) still gets processed even if I don''t render to the screen. Or perhaps I could throw in a hack that locks the frame rate to a constant 60fps for a few seconds, and then release it to full throttle. Does any of this sound reasonable? Rasta

Share this post

Link to post
Share on other sites
Well, it sounds like your sprites are jumping around the screen because they don''t know that you paused for a few seconds and they try to update their positions really fast to try to make up for their being behind schedule. I would have to look at the code to really know, but it''s possible that all you need to do is subtract the amount of time you paused from your time var... that would only work if you aren''t working with the actual time, but with a time difference or something... otherwise, I don''t know. By the way, I wouldn''t suggest using Sleep(), because it makes all processing impossible, considering it gives control away for however long you are sleeping for. A more realistic way of pausing would either a.)define an IsPaused flag and divert the program flow to a PauseHandler function or something instead of doing the usual game processing, or b.)Have several game states, (ie. GAME_PLAYING, GAME_START, GAME_PAUSE or whatever ) and simply have a handler function for each state, or something... you''ll figure it out.

Share this post

Link to post
Share on other sites
The reason why I use Sleep() is that I am in the middle of a function
and I want to return exactly where I left off. If I change game states,
I probably couldn''t do that. And all my processing flows in a single loop.
Any real pausing will stop everything, game logic, input, rendering, etc..
I have something like this:

while(1) {

if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) break;


if(active && running) {

// game timing done here

if(game_state == GAME_STATE_START)
else if(game_state == GAME_STATE_PLAYING)
else if(game_state == GAME_STATE_PAUSED)

// etc

else {

I''m actually using Sleep() inside the function Game_Playing() where I
am loading data for next level. I use Game_Paused() to pause the game
while playing the level. I can successfully change the state of the
game to Game_Paused from Game_Playing and back again without any jumpy
sprite movement, probably because my game flow does not stop. But
Sleep() seems to throw my timing off a bit.

Share this post

Link to post
Share on other sites
Hey there, in my game the game loop never stops until you quit. The way it works is my main game loop. Just calls other functions like "Update_Units", then "Paint_Units". Well actually it''s a little more comples than that, but the idea is the updating of the units and the painting of the units is seperate so when I pause I just stop updating there position, but still paint. Now the reason I do this is for things like in game menus where I''ll need mouse.

Now this will fix the thing about not using the sleep function. However the thing about them jumping. I think what DerekDay said is about right. In my game the time is all in milliseconds, I think from midnight. But that''s not the point. Timing is always the difference from two points in time. So for your guy if the last timing value was 5000ms after midnight and the next timing val was 5050ms after midnight, you would simply calculate according to that units speed, where it should be right now. The problem comes when it goes from 5000ms to 8000ms (We haven''t updated for 3 sec) so you could caculate the next position. But if you don''t want him to move you could replace the old and new timing var with the current time (So it would calculate no move)(This sound like my personal favorite) or if let''s say you paused for three seconds then subtract 3000ms from the origanal timing variable.
Anyhow I hoped that helped.
See ya,

P.S. I''m a programmer not an english teacher, expect spelling errors!

Share this post

Link to post
Share on other sites
Hi Rasta,

I agree with cyberben. The way I would do it is continue to draw your screen (with maybe a "Paused" thingy overlayed), but not update game state. When the game is unpaused, simply set the previousTime (the var you compare to current time calculate the change in time between updates) to the current system time or whatever. Then when updates resume, it will, as cyberben said, be none the wiser that your game even stopped.


squirrels are a remarkable source of protein...

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

Thanks, I fixed it! All I had to do is reset my timing variables
that hold the count difference between the frames like:

QueryPerformanceCounter( (LARGE_INTEGER* )&(high_start) );
high_end = high_start;

And it seems like no time has passed. This works better than
passing a fake frame_time like zero to my game functions. Thanks!.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!