itch.io is community of indie game creators and players

Devlogs

Supporting all display frame rates

Fracas 3
A browser game made in HTML5

I upgraded from a laptop with a 60Hz display to one with a 120Hz display, and suddenly Fracas 3 played at 2x speed. I instantly regretted hardcoding my game(s) to expect 60 frames per second. I remember folks making similar mistakes with CPU clock speeds, a million years ago. I wonder how many people have tried to play this game and thought “oh dang that’s way too fast”? Or too slow?

Anyhow, I switched to using the actual measured time between frames to decide how much to advance the world clock, instead of assuming every frame is 16 milliseconds.

It took a few tries to get right. I needed a little extra code to get it to work with pausing and stepping. And I didn’t bother with using the visibility API to check for tab freeze/unfreeze caused by tab switching etc. Hackily, I forced each frame to never be more than 2x the length of the previous one, which is robust and simple, even if it’s not absolutely perfect.


Files

  • fracas3.zip 1.2 MB
    Feb 23, 2023
Leave a comment