Jump to content
  • Advertisement
Sign in to follow this  
BlueBan007

how to make a pause function?

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

ok, I have a game loop, and I used to have a simple pause function like pause->resume... now im trying to implement a pause "menu"... heres what I have that just gets stuck in the pause menu: init all... ... ...
if(keyDown(SDLK_p)){paused=true;}

		 while(paused==true){

			if(keyDown(SDLK_SPACE)){paused=false;}

		 PAUSE_::gamePause();

			redraw();
		 	cls();	
			
			
		 }

... ... redraw(); cls();

Share this post


Link to post
Share on other sites
Advertisement
I think that you need to separate the player's input from the player's input. You should be doing something like the following:


game.getInput();
game.update();
game.pauseUpdate();


and the function getInput() gets the user's input; the update function updates the game/player states; and pauseUpdate looks something like:


void Game::pauseUpdate()
{
if ( Paused )
{
// navigate thru pause menu logic
}
}


You should NOT conflate user input stuff with navigating menu stuff. It is very bad. It is best to use a modular design. The user input function should only process user inputs and the pause menu update function should only navigate thru the logic of the menu.

Edit: Since it appears that you are using SDL (in C++) see my last post on SDL input event loop. In this post I write down a simple event loop skeleton function for SDL (you can fill in specifics, of course).

This is a user input function that I use. Other functions in my game obviously use this information; the only restriction that is placed is that the user input function ONLY processes user input.

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueBan007
Thank you very much for pointing me in the right direction!
(:

No problem.

I just wanted to point out one more subtle point, just in case it is not already known:

In the event loop that I posted, it can keep track of key presses/releases and other types of input. Here are some important points:

1. If you in the future need to process joystick input you can add the joystick event detection here. If you would like an example, I can post my code that accomplishes this too (the one I linked to in the post above does not handle joystick events).

2. For the case of key (press / release) you can create a member variable of the user input class called bool key_a (the 'a' key, for example).

When you detect a keypress event for key 'a' you set the bool key_a = true; and when you detect a key release event for key 'a' you can set key_a = false. Just repeat the process for all keys that you need to keep track of. That way you'll have handy booleans to use for whenever you need to know whether or not a user is pressing a certain key.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!