pausing in a game?

Started by
6 comments, last by Rob Loach 18 years, 10 months ago
how would i do this in my game in the structre, whats the simplest way.
Advertisement
while(pause){    if(keyboard.hit())        break;    pause_screen.draw();    sleep(100);}


[Edited by - Boder on June 4, 2005 9:04:30 PM]
You can:
> Make it freeze until a key is pressed, as Boder states
> Prevent your game from updating certain objects, and only have them draw (this will only work if your objects have two separate functions for stepping and drawing, where drawing will not update anything)
For a more detailed reply, we need to know the basic structuring of your game.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
It kind of depends on how you are hanfling game states. With this system it's pretty easy, and with the Task/Kernel system it's pretty easy. How you deal with game states is going to define how you handle a pause.
The best way to predict the future is to invent it.
Make a game state manager which handels the game state of the game and then set the game state to pause. Which would stop all loops and draw a screen of some sort, or just grab the current screen image and dim it and write the word "paused" in the center.
The easiest way to do this is just to have a flag declared in your main game loop. Set it to true when paused, and false when not paused. Then you can use this to decide how to handle your game loop (most likely, handle window messages, read inputs (but discard anything not pause-related), and refresh display.)

If you're using an object-oriented approach to your game, you could just have a "isPaused" member in your class which can be used to determine how to handle stuff. For instance, the map class in an RPG might only redraw the map and skip the code that handles NPC/player movement when this flag is set.
thanks guys and my structure is not in OO design because i am a newbie so basically i have intiliase sprites/objects render objects then i have my game loop
which the render functions go in and the controls and any conditions
Game states are definately the way to do it. You'd have one state for InGame and another called GamePause or something and then when the player presses the pause button, switch between the two. The article ricekrispyw posted looks pretty good, I suggest you look into it.
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement