The reason the funny behaviour happens (if your frame-limiting uses Millisecs()) is because Millisecs() is a global constant value, and doesn't pause when your computer does. (I'm getting weird deja vu posting this, and I feel like I did the last time I posted it... anyway...)
Millisecs() is the total number of millisecs since you last turned your computer on, so it's not going to stop for your program.
When your program has an event loop, a timer with Millisecs() finds out the difference between the last time it checked the millisecs. By doing this it finds out how many millisecs have passed since the last loop, and converts this into frames according to the FPS speed you specified.
The thing is, if you've ALT+TABBED out of your game for 10 seconds, and then return, then a game running at 60FPS has 600 frames to catch up with. The frame-limiter calculates this and calls 600 frames in order to catch up. Not only does your game jerk to a halt for a few seconds, but depending on how it's set up, especially with commands like UpdateWorld, some really weird stuff can happen!!
To combat this, I usually implement a simple thing which goes like this:
Millisecs() is the total number of millisecs since you last turned your computer on, so it's not going to stop for your program.
When your program has an event loop, a timer with Millisecs() finds out the difference between the last time it checked the millisecs. By doing this it finds out how many millisecs have passed since the last loop, and converts this into frames according to the FPS speed you specified.
The thing is, if you've ALT+TABBED out of your game for 10 seconds, and then return, then a game running at 60FPS has 600 frames to catch up with. The frame-limiter calculates this and calls 600 frames in order to catch up. Not only does your game jerk to a halt for a few seconds, but depending on how it's set up, especially with commands like UpdateWorld, some really weird stuff can happen!!
To combat this, I usually implement a simple thing which goes like this:
; Calculate number of frames depending on difference ; between the system timer, and the last time we updated ; our code to catch up with it. ie the number of millisecs passed milli# = Millisecs()-Timer frames = milli/(1000/FPS) ; convert to frames If Millisecs()-Timer>3000 ; If more than 3 seconds have passed since the last ; time round, then we must have ALT+TABBed, coz ; the game should not have run that slowly. ; Set timer = Millisecs() to catch up with the system clock Timer = Millisecs() ; Set number of frames to 1 instead of what it was. Frames =1 End If For k=1 to frames ; Update game code Timer=Timer+(1000/FPS) . . Next