How to limit FPS with Phaser 3?

Trying to limit the FPS in my game to 15 fps by setting the config as follows:

var config = {
type: Phaser.AUTO,
width: 400,
height: 400,
fps: {
target: 15,
},
scene: {
create: create,
update: update
}
};

But the value on fps::target doesn’t make any impact whatsoever. Am I missing something?

Try it in the physics instead:
physics: {
default: “arcade”,
arcade: {
gravity: { y: 200 },
fps: 50
}
},
At least for arcade

Sorry to say it doesn’t work…

It’s weird, doesn’t work for me either this way. Might be a bug. Following works for me though:

// Somewhere in your scene code
this.physics.world.setFPS(15)

Note that this will limit only the game simulation update rate and not the rendering rate.

Nope, that doesn’t work either. I might be doing something wrong in my “setup”.

Here is a link to the code with game logic that works as expected (its a simple snake-game) but with the fps-limitation not working: Snake game in javascript with Phaser 3.

Still, fps config option is not working.

Does anyone have a solution for this? I’m creating a game in Phaser 3 that needs an FPS lock.

I’m quite sure you can not limit Phaser 3’s FPS.

I’m interested in this too. I’m creating games to be used on tablets and phones that don’t need high fps, and it would be awesome to be gentle on the power consumption.

@prob Really? There should be a way to do this.

I’m with @glantucan! I would really like to see a solution for this. Albeit, hacky or not.

Thanks for that reference @samme. At least we know there might be a solution coming eventually and some of us can patch our phaser copy.

source code already show

in config:

fps: {
    target: 30,
    forceSetTimeOut: true
},
2 Likes

Hi @samme ! Could you kindly explain your solution ? I am kinda lost. When I added fps in config as shown below, my game moved faster. Been trying alot of solution provided by others, but to no avail. Will appreciate if you could help me out. Thank You ! :’))))))

var config = {
type: Phaser.AUTO,
parent: “game”,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: 1000,
height: 1200,
},
physics: {
arcade: {
gravity: { y: 0 },
debug: false
}
},
fps: {
target: 120,
forceSetTimeOut: false
},
scene: {
preload: preload,
create: create,
update: update
}
};

If you want to limit FPS, use

fps: { forceSetTimeOut: true, target: 60 }

or a target smaller than 60.

But without forceSetTimeOut: true there will be no limit.

Thanks for your reply, @samme . Not sure why, but it is not working for me. When forceSetTimeOut is true and target is 60, my game moves faster. Besides placing fps in config, may i know if there is anything else that you did differently ??

What’s the original problem you’re trying to solve?

@samme On computers with high refresh rate (144hz) , the game moves faster but on computers with 60Hz, the game moves slower. I want to maintain the game speed on all computers with different refresh rate.