Pausing an application

Blitz3D Forums/Blitz3D Beginners Area/Pausing an application

767pilot(Posted 2004) [#1]
How can you pause an application?

I want to be able to press the spacebar and the application will pause, when i press another key it will resume.

I looked for a pause or halt command but with no luck

thanks


soja(Posted 2004) [#2]
1) Monitor for a spacebar keypress
2) When it happens, change a global gamestate variable to a value (of your own choosing) that signifies "paused"
3) When it comes time to draw your screen, instead of rendering the game display, render a paused display instead.
4) When unpause occurs, change the gamestate variable to "playing"

So in your loop (that occurs multiple times per second), you would have something like this (perhaps):
Const GS_PLAYING = 0
Const GS_PAUSED = 1
Global gamestate = GS_PLAYING

While Not KeyHit(1)
  Select gamestate
    Case GS_PLAYING
      ; Draw Game, check for game keypresses, etc
    Case GS_PAUSED
      ; Draw paused screen, check for unpause keypress, etc
  End Select
Wend



Rimmsy(Posted 2004) [#3]
or for a quick pause try: waitkey. it waits, as the name suggests, for a key to be pressed. Also, mousewait. Note: The game will be completely stopped until you press a key or click the mouse.

Soja's example is the right way to go if you want a pause screen or something similar.


big10p(Posted 2004) [#4]
If you use WaitKey(), I think you'll need to FlushKeys first or it won't work properly. Something like:

If KeyHit(57) then FlushKeys : WaiyKey()