Different game speed on different monitors

When I tested the game on my main monitor, everything was fine. But now I’ve changed monitors and some things are very slow and some things are very fast. How do I fix this?
Game - 2D platformer

Sounds like you might have some framerate dependent code. V-Sync might change your framerate depending on the monitor you are using, and thus impact your game speed if your code does not account for different framerates.

It’s hard to say what exactly is wrong with your code without seeing it, but generally, try not do do things like “Add 1 to X position”, as if the code runs at 30 FPS, the object moves 30 pixels, but at 60FPS it moves 60 pixels every second. Instead, do something like add 1 * TimeDelta(), since TimeDelta() is the time elapsed since the last frame, and thus the object would always move the 1 pixel every second regardless of framerate.

2 Likes

The saddest thing I know about timedelta(). And I also noticed that on a new monitor, just a second after starting a scene, the frame rate drops sharply. And that’s why everything slows down. Now just need to understand why it slows down.

Keep in mind monitor refresh rate directly interacts with the max framerate of the game.

If your max FPS is 60 on your project, and the monitor’s refresh rate is 144hz, they will see framedrops. This is a side effect of Chromium/Electron forcing Vsync, and vsync requires the FPS to be an even divisor of the monitor refresh rate and an even divisor of the original framerate.

e.g. If your max FPS is 60, and their refresh rate is 144hz, the FPS will drop to 48 as that’s the nearest number with a shared divisor for both the 60 fps and 144hz. A 240hz monitor will have no issues as 60 is an even divisor of 240.

This may not be related to the issue, but it’s always a good thing to check.

(I think this is the third time this week I’ve mentioned this, so if it is the issue, you’re not alone. Unfortunate side effect of Vsync.)

4 Likes

Just a question from a non-technical person, what is the best way to prepare your game for this contingency? Would setting the maximum frame rate to 0 in your game properties solve this? If so, would there be any negative implications for game play?

I’ve not found any perfect solution, although this isn’t unique to GD5.

If you have any frame dependent logic (much like Arthuro mentioned above), setting a max framerate of 0 would mean faster PCs would run the game MUCH faster than on others. Also, on some PCs it could run at 1000s of frames per second leading to GPU/CPU overutilization.

Personally, I do my best to avoid any frame dependent logic (much like Arthuro mentioned by using timedelta), and I generally set my max FPS to like 240fps. It’s not perfect, but seems to cover most scenarios I’ve run into.

3 Likes