Pause the game, pause the timers

Blitz3D Forums/Blitz3D Programming/Pause the game, pause the timers

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

What I do is to use a relative game timer that's updated by the amount of time taken by the previous loop at the start of each new loop.

eg.

; Untested code.
; 'game_time' holds the time value which should be used with all pausable time_out routines.

Global game_time
Global old_time
Global millisecs_time
Global time_out

old_time = MilliSecs()

Repeat

millisecs_time = MilliSecs()
the_time_taken = millisecs_time - old_time
game_time = game_time + the_time_taken
old_time = millisecs_time

If game_time > time_out
time_out = time_out + 1000
EndIf

If KeyHit( pause_key )
; -- Process pause event --
old_time = MilliSecs() ; Re-initialize 'old_time' after the pause.
EndIf

Until KeyHit( 1 )