Skip to content

realtime_interval and key_repeat_interval are browser-dependent #949

@pancelor

Description

@pancelor

A comment from a puzzlescript dev that I just stumbled across on discord:

It's weird that in firefox it's like 3x times slower, hard to nail the gamefeel for all browsers alike. Sorry to those who played on Chrome!

Apparently key_repeat_interval acts differently across browsers? So I made a test file: key_repeat_interval.txt. I set up a situation with key_repeat_interval that should have taken 10 seconds, and manually timed it (with my phone's stopwatch) in each browser. In firefox it took 10.03 seconds, but in chrome it took 13.21 seconds. that's much much slower than it should be!

(I observed similar results for realtime_interval.txt -- 10.00 seconds in firefox versus 14.17 seconds in chrome. I did not test again_interval but I would guess it has similar issues)


I suspect this happens because puzzlescript uses setTimeout(loop,17) to draw frames; as far as I know requestAnimationFrame is the "correct" way to run a HTML canvas game's mainloop. I don't know where I first heard that but I did a bit of searching and found some web resources that seem to agree:

  • this tutorial talks a little bit about why you would want requestAnimationFrame instead of setInterval
  • MainLoop.js, a game loop library that looks well-thought-out, and uses requestAnimationFrame

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions