The whole idea of using the timer for gaming is not the best. The newer approach is using
window.requestAnimationFrame
. Please see:
http://paulirish.com/2011/requestanimationframe-for-smart-animating[
^].
Note the use of the fallback to
window.setTimeout
in the code sample.
The pausing of the game is pretty much trivial. You simply create some flag variable for paused/running state and don't process frames when the game is paused. You can see the complete code sample (sorry, it's not really minimal, is a fully-fledged game, but finding the technique is similar, please see
states.paused
in the code), for example, here:
Tetris on Canvas[
^].
—SA