Archived

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

AndreTheGiant

how do you implement Pause?

Recommended Posts

Hi It seems to me that a simple feature like being able to pause your game would be harder to implement than most people think. Im not sure how you would have all your drawing stop, and keep drawing the same screen until the game is unpaused. Also, when the game is unpaused, you would have to reset all of your timers to the time that the game was paused so that there are no hiccups or sudden speed jumps in game play. Is there a generally accepted method to implement pause functionality in games or does it pretty much differ from game to game? thanks! ----- It''''s not my fault I''''m the biggest and the strongest; I don''''t even exercise!

Share this post


Link to post
Share on other sites
I have one variable which contains the number of milliseconds passed since last frame. This variable is updated for each poll and is used for ALL animations and movement.

When the game is paused just set this value to 0 and run your gameloop as usual. This way all movement and animation will stop. Your timers are unaffected because you add 0 to them.

Should work.

[edited by - granat on March 16, 2003 12:51:49 PM]

Share this post


Link to post
Share on other sites
A simpler more brute method is to check for a keypress and if the pause key is pressed you go into a while(true) loop that breaks when the pause key is pressed again

Share this post


Link to post
Share on other sites

  
while( !bDone )
{
if( !bPaused )
GameLogic( iTimeSinceLastFrame );
UpdateKboard( );
// ...

Render( );
}

??
If the game is paused, just dont do any more game logic. Sound good to me.

Share this post


Link to post
Share on other sites
Yeah, the main point here is that your drawing code should be separate from your updating code. If they''re all cozy with each other, it keeps you from being able to do this.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
just have a variable that controls all movement, delta, and when its paused set it to 0. you can even do some cool stuff by having more than one delta so you can have environmental effects keep going while paused, it looks kinda cool to have the players stopped but water and particles still moving and stuff like that.

Share this post


Link to post
Share on other sites
Yea i kind of figure it would involve some sort of jiggering with the timesincelastupdate variable, i was just wondering if there should be more to it than that.

Eskhan, your method only does half the job doesnt it? Sure it would stop the movement, but when you unpause, everything would jump way ahead because your timeSinceLastUpdate would be however long the pause was. So for example, if a race car is supposed to move 4 units a second, when you pause, the car will stop, but say if you were paused for 1 minute, than as soon as you unpause, suddenly the car instantly zooms 240 units ahead and then continues travelling at 4 units/sec.

But anyway, i think i get the jist now. Thanks all!

Share this post


Link to post
Share on other sites
The way I do it is that physics/movement is not done while paused, just drawing, message processing, and keyboard input (and all inputs are ignored unless it''s the key to unpause). You shouldn''t do a DOS-style loop waiting for keyboard input; it''s bad to ignore Windows messages for a while.

~CGameProgrammer( );
DevImg.net - Post screenshots, comment on others.
Town 3D Engine - A city-rendering 3D engine. Download the demo.

Share this post


Link to post
Share on other sites
quote:
Original post by billybob
just have a variable that controls all movement, delta, and when its paused set it to 0. you can even do some cool stuff by having more than one delta so you can have environmental effects keep going while paused, it looks kinda cool to have the players stopped but water and particles still moving and stuff like that.

Better yet have all of your draw() methods take a (double& rElapsedTime) argument, allowing you to just pass 0 to them...same idea, i''m just thinking object oriented...and I''d be afraid that this "variable" is global.

- sighuh?

Share this post


Link to post
Share on other sites
nope, its in my level class, there are actually 3 deltas in the engine section of my game, every object class has one delta that gets initialized for you. it has an enumeration that tells it what delta to use, and then an update function taking all 3 of the deltas. the function looks at the enumeration, and takes the correct delta. this way, i can set particles that don''t affect the game to the ''environment delta'' which doesn''t pause but is affected by game speed. game classes use the ''game delta'' which is paused, affected by game speed, the works. then i have a ''system delta'' that is just pure delta, always.

Share this post


Link to post
Share on other sites
You''re quite right Andre, if you are doing proper timebased movement in such a way that...

ticksSinceLastUpdate = GetTickCount() - LastUpdate;
LastUpdate = GetTickCount();
Position += ticksSinceLastUpdate*Veloctiy;

You would have to do the following when you unpause game
LastUpdate = GetTickCount();

Otherwise you''d have large jumps upon unpausing the game

Share this post


Link to post
Share on other sites