The best example I can think of is Doom 3. It seemed to me that if there was any kind if lag the game would pause and then resume without "fast forwarding" to catch up. I'm trying to figure out a good practice to use for lag detection in JavaScript.
|
|
First Rq : A key rule in Javascript : avoid system lag, with a very simple principle : do not feed the garbage collector. Now that you've done that, to avoid a slow-down/ fast forward behaviour, you have to to handle the time and timers by yourself. And drop a frame or more if you have to. Rq : A secondary benefit of handling your game time/timers is that it will allow to nicely pause the game, and even to go faster or bullet-time if you want. So how to handle your game time ? And for the game timers either :
(you can write this in a neater way with a : if (this.shouldTurn()) ... ) So now that you have your game time, you must have your entities update depending on game time : So with delta = delta between current game time and previous frame game time :
Notice that window.performance.now is a much more accurate timer available (with a polyfill) on almost all current platforms. |
|||||||||||
|
