PuzzleScript icon indicating copy to clipboard operation
PuzzleScript copied to clipboard

switch to requestAnimationFrame() for drawing

Open pancelor opened this issue 1 year ago • 0 comments

This is essentially the same code as #924, with this additional code to make sure deltatime is accurate

var prevTimestamp;
function loop(timestamp) {
    var deltatime = 0
    if (prevTimestamp !== undefined) {
        deltatime = timestamp - prevTimestamp;
    }
    prevTimestamp = timestamp

This was the solution suggested by the docs; I should have seen it and included it last time!

Warning: Be sure to always use the first argument (or some other method for getting the current time) to calculate how much the animation will progress in a frame, otherwise the animation will run faster on high refresh rate screens. Check the example below for a way to do this.

pancelor avatar Dec 20 '22 13:12 pancelor