Sign in to follow this  
Eralp

How to pause the game loop ?

Recommended Posts

Hi :) I'm new here and i want to ask how to "pause". I dont know the proper way. If i was just going to stop the game then it would be easy but i want to draw a sprite too,while the game keeps its current position at the background. The first one is easy,the second one is easy but i cant do the third one :P My technique; at the while loop in winmain there is a switch(gamestate). if gamestate is 0 then call the normal game render_frame, if the game state is 1 then call the render_frame_pause. Is this the proper way to do the pause-menu thingy?After that i have to take care of the game-as-bg thing. Have a nice day =)

Share this post


Link to post
Share on other sites
Well you game likely has multiple systems. Just put a...

if (!pause)
{

}

for each system that you want to be paused when the game is paused. The game that I've developing has multiple systems, and each system is built like a class, and at any give time the class has a state variable so that the other systems know its status, such as loading, loaded, ready, paused, exiting, error, idle, etc. Using state variables for each of your systems might be handy.

Share this post


Link to post
Share on other sites
oh i got it thanks for your reply.
I asked the background thing in the directx forum.I think they will be more capable to answer since im using directx :D
thanks again

Share this post


Link to post
Share on other sites
I recommend creating a "game state" interface, with virtual update and draw functions. You create a class that implements the interface for each state there is, like "playing" and "paused". Then you make a stack of pointers to game states. To start a new state, you just create a new instance and push its address onto the stack. You can very easily make it only update the top instance on the stack, but make it draw all of them, in bottom-to-top order.

Share this post


Link to post
Share on other sites
Most of my game subsystems are updated with an elapsed time value garnered from a clock or timer someplace. When I pause the game, the timer that drives the game has its Pause() method called, which causes it to stop computing elapsed time (and thus always return 0), while the clock that drives rendering updates remains unpaused.

The result is that the game effectively stops updating, since everything is based on time, but rendering can continue.

Although the real system is actually much more involved than that, this is basically sufficient in many cases.

Share this post


Link to post
Share on other sites
Your post implies that you are not separating your render and update code, which might cause issues down the road.

Break out your gameplay and your rendering code, and it should become very clear how to handle this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this