Cannot use 'this.physics.world.setFPS' to set FPS update rate?

Hello everyone,

I was going to create an issue on the tracker, but I figured I would check here first just in case I am messing something up.

This is my problem:

Example Here

According to the docs, I should be able to use this.physics.world.setFPS to limit a scenes update rate. However, using this method from within a scene doesn’t seem to work.

In my example above I have set up a simple scene.

Here’s what I think it does:

  • Creates a tick variable
  • Sets the physics world fps to an arbitrary value
  • Every update the tick is incremented
  • If the tick is greater than 500, the time elapsed from the start of the game is printed

As you can see in the example, the time elapsed remains (roughly) the same even if you change the framerate in the setFPS method.

The behaviour I expect is that if the update rate is doubled, the time would halve.

This issue became apparent in a game I am working on, where everything becomes ~twice as fast when a user has a 144hz monitor.

It seems to affect both FireFox and Chromium

Perhaps I am being stupid, but I think there might be a bug or incorrect documentation.

You can not set the render rate with Physics.

Docs:
“This frame rate is independent of the frequency at which the game is rendering. The higher you set the fps, the more physics simulation steps will occur per game step.”

Look at this topic:

1 Like

Judging by your example, you’re confused by what setFPS actually does.

A scene’s update method is called on every frame of the game loop. The game loop uses the requestAnimationFrame API provided by the browser and its speed is tied to the refresh rate of the player’s monitor. You cannot directly limit or control how often update is called. Any code that runs in this method should not behave differently whether it’s called 60 times a second or 144.

The setFPS method relates solely to the Arcade Physics engine and will only affect game objects controlled by it (i.e. ones added through this.physics.add). Arcade Physics runs separately from the scene. It is independent of the speed of the update loop and will always update at a fixed time step - by default, 60 FPS. Increasing this frame rate with setFPS makes Arcade Physics perform more updates in smaller increments, which can sometimes help with accuracy at the expense of performance. The FPS of the fixed time step does not affect the speed of the physics simulation.

The scene’s update method receives two arguments - time, which is the current time in milliseconds, and delta, which is the time elapsed since the last frame. If you want predictable timing from your update method, create a fixed time step by accumulating the values of delta to keep track of how much time has passed.

1 Like

Thanks very much for the detailed explanation and solution.