Pause the game, pause the timers
Blitz3D Forums/Blitz3D Programming/Pause the game, pause the timers 1) Every game I've ever written (In 20 years or so!) has had a game_clock variable.
2) Pauseing games is one of those things that is never as easy as it seems.
3) I don't actually understand your problem so I'm not going to be very helpful.
2) Pauseing games is one of those things that is never as easy as it seems.
3) I don't actually understand your problem so I'm not going to be very helpful.
Have you tried updating the gun_timer variable to the current time after unpausing the game.
onPause
store current time
onUnpause
offset = time - stored time
add to all timers like the one above
store current time
onUnpause
offset = time - stored time
add to all timers like the one above
ah yeh zombiewoof got it,
say gun_timer is 1000 and time is 1100,
*game is paused*
pause_time=1100
*game is unpaused*
new_time=2000
offset=2000-1100=900
gun_timer=1900
which means there is still 100 milliseconds til the next firing time.
thanks
say gun_timer is 1000 and time is 1100,
*game is paused*
pause_time=1100
*game is unpaused*
new_time=2000
offset=2000-1100=900
gun_timer=1900
which means there is still 100 milliseconds til the next firing time.
thanks
Funny how some questions/problems open my eyes on other things... :)
Thanks guys !
Thanks guys !
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 )
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 )
You have to be careful if you're using 3d tweening code, it stalls until the tweening code catches up.
Ah yeah I am using tweening code and the timer thing didnt work, because now I can fire continuously with no delay - oops.
I dont have a clue what Axemans code does either arrgghh!!!!
am i doing something wrong?
I dont have a clue what Axemans code does either arrgghh!!!!
If KeyHit(57) FlushMouse If paused=no paused=yes pause_time=time Else ;set timers offset_time=time-pause_time For s.ship=Each ship s\launch_timer=offset_time Next paused=no EndIf endif
am i doing something wrong?