Advertisement

Pausing a game

Started by February 05, 2001 04:26 PM
12 comments, last by penetrator 23 years, 9 months ago
How can I manage to pause the program when pressing a key ?
this is extremely difficult to do.

in opengl, you might try passing pointer nodes into a temporary datastream in order to shutoff any external processing or graphic handling.

in direct x the best way to go about this is to utilize DX''s hTime and UNITOUT functions. merely pass all outputting vertices to DX''s timeout matrix, to retrieve it, use hTime to recall any lost parameters.

Advertisement
mainloop()
{
if ( !programpaused )
updateprogram();
}

http://members.xoom.com/myBollux
zedzeeks code is severely flawed, it doesnt even handle vector mipmaps!

In opengl I just use a variable (multiplier) which stores how much should be changed every cycle, for example if I want my character to move I could say x+=multiplier*speed or something like that. If you want to pause the game you just make multiplier = 0. I am making a game using this and am pretty far along, it''s for mac though.
I generally use timers for everything. Then, to pause, you tell all your objects to pause, and they pause their timers. This is achieved by setting pauseTime to the current time, then when unpausing, finding the difference between current time and pauseTime and adding that to the timer start variable.

Come to think of that, a pause() function in my timer class would be really useful, and I think I might keep a static linked list of all new timers to be able to pause them all automatically.

After that, zedzeeks code should be ok, except that I''d still render the current screen (it will be static since all your timers stopped), and overlay a paused image, or your alpha''d blue quad like UT.

Cool

~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL
~~~Cheers!Brett PorterPortaLib3D : A portable 3D game/demo libary for OpenGLCommunity Service Announcement: Read How to ask questions the smart way before posting!
Advertisement
Umm why not have a variablo as boolean.
bPause for example

If (bPause = False)
{
DoFrame, draw Vertices, update matrix and everything else.
}

If it is paused then nothing will happen, IE it is paused which is what you want, no ?
How ever you might want to keep checking for Input from Keyboard, mouse etc so you can unpause it.
Why is this thread so funny?

penetrator: you do have a WndProc do you? Why not catch the WM_KEYUP or WM_COMMAND and set the boolean bPause to true;
After that don''t call your Animation() proc when bPause is true;
You did split your Drawing and Animation/Movement or not?

Above method even includes multi-dimensional-procedural-vector-mipmap-lookup-tables, but I somehow forgot to add this peace of code - sorry

this is something else but if this was fullscreen(no need to refresh), then all u have to do is to fall in a continuous loop that checks for unpausing?
and maybe it''ll be better if u add like Sleep(20) for each iteration so it doesn''t take up 100% of the cpu.

just wondering, cuz i made a java game b4 and i had this problem w/ refreshing while paused but i don''t c this as a problem if it''s fullscreen.
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
Hi,

If you use the multiplier method suggested by david20321 then you pave the way for a whole host of nice little special effects.

Two examples -

1. Have different multipliers for different classes of things in the game. Obviously players, AI players, bullets, etc should stop when you press pause. But you could carry on updating other ambient features, such as flickering/pulsing lights, or animated textures on monitor screens. A more comedy effect can be made by adding some moving characters (insects crawling on the floor, even a cleaning lady that mops the floor around any characters onscreen if you like ), although unless you're writing a Police Squad based game, maybe not...

2. It can be used not just for pausing, but for The Matrix style 'bullet time' effects. i.e. you can slow down time if you like. You can add a slow motion mode to your game by changing the value of _one_ variable (the multiplier).

The version I use uses the time passed since the last frame (in seconds) as the multiplier. So if I get 100fps, my multiplier will be 0.01. If I define my character as moving 1 meter per second, then after being multiplied with the multiplier, then this frame it should move 0.01 meter (1 centimeter). As david20321 said, by setting the multiplier to 0 each frame (after the real one is worked out), your game will pause itself.

Dan

Edited by - danbrown on February 6, 2001 2:42:17 PM

Dan

This topic is closed to new replies.

Advertisement