How do you pause a game?

Started by
15 comments, last by eektor 17 years, 8 months ago
Quote:Original post by eektor
Is there a book or a tutorial that talks more about managing game states? Right now all I have for game states are Menu, Instructions, and Game.


You should check out Managing Game States in C++, i think it's quite a good tutorial about that topic.

-Raven
Advertisement
Well i'm a newb, but the way I do it... When ur collecting input if they press say Space, just call a function that doesn't return until they hit space again. Since everyone else has a lot more complicated ways mine is prolly newbish and has a problem... but I don't see what, does everything I need it 2.
If you want to stop some behaviour from happening (e.g. the ball moving) then testing a flag inside the movement code itself is less efficient than simply not calling the movement function in the first place. It's also messier.

If you were to implement time-based movement (so that the ball moves at the same rate regardless of framerate) then you could also approach this by simply telling the ball that no time has passed. You literally 'stop the clock.'

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I can vouch for the link RavenMokel posted, using a stack-oriented state machine confused the life out of me until I saw this link in another post. Very simple examples and source as well as a good example of polymorphism at work.
Thank you Raven for the link. I might get the books listed as resources too. I got the first one already.

Thank you superpig you just made me realize an error. I was wondering sometimes when it was paused once I unpaused it someone will score and the ball starts at the middle again. I forgot I didn't stop the timer and the ball's movement is time-based.

@Cleric Kain I was thinking of doing that but I wanted to give the user the option to quit at any time and not have to unpause then quit.
Thats easy, just make it so it returns if they hit escape or space. Should be able to do that np
Ok, I think I got the pause working alright except for one bug. If a person press p sometimes it stops like its supposed to but other times it pauses and then resumes. I believe somehow the program reads the p key being pressed down more than once when you only pressed it down once.

How can I avoid this? I use SDL and I was trying to put a SDL_Delay like this:

// If user presses 'p' pause or unpause the gameif (g_input->getInput(SDLK_p)){	if (g_pause == false)		g_pause = true;	else		g_pause = false;	SDL_Delay(75);}


I've been trying to vary the SDL_Delay as well but with no success. Any ideas?

This topic is closed to new replies.

Advertisement