0

I'm trying to make my game pause if the user presses the 'P' button, and then unpause again with the P button. The pausing works when it's only pausing:

game_state = PAUSED;

I've currently tried the following with pausing and unpausing - none have worked:

switch(game_state)
		{
			case RUNNING:
			{
				game_state = PAUSED;
				break;
			}
			case PAUSED:
			{
				game_state = RUNNING;
				break;
			}
			default:
			{
				game_state = PAUSED;
				break;
			}
		}
if(game_state == PAUSED)
			game_state = RUNNING;
		else if(game_state == RUNNING)
			game_state = PAUSED;
if(game_state == RUNNING)
			game_state = 500;
		else if(game_state == PAUSED)
			game_state = RUNNING;
		if(game_state == 500)
			game_state = PAUSED;

I've also tried other things similar to the ones above. Does anyone know a way for this to work?

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by prushik
0

The switch should work just fine. Make sure that your game loop is checking it appropriately and that you haven't defined the RUNNING and PAUSED constants to be the same value (by copy-paste oversight or whatever).

0

The switch should work just fine. Make sure that your game loop is checking it appropriately and that you haven't defined the RUNNING and PAUSED constants to be the same value (by copy-paste oversight or whatever).

All of that's fine. If the switch statement is good, then I think the problem is with keystrokes. I'm not checking to see if P was just pressed, but just if it's down. I had the same problem with mouse buttons. I would have to have prevkeystate[] as an array or something to check if the key was just pressed.

0

I encountered such a problem when one of our programmers, by pressing keys ESC (pause the game) disable the rendering. The engine was designed so that events are not intercepted when rendering was stopped (and this is quite logical).
Try to arrange a pause in some other way. For example:
at the time of rendering a new frame, define the state of the game "freezes"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.