Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

Ways to limit Phaser3 update rate?

$
0
0

In my Phaser3 game there is a global gameTick variable that is incremented every update. I am using this to spawn in enemies in my game every 100th update.

Here is a simplifed example of what is going on in my scene class:

update () {
    global.gameTick++;

    if (global.gameTick % 100 === 0) {
        this.spawnAlien();
    }
}

This works fine but as soon as a user plays the game on a monitor with a refresh rate >60hz the update timing breaks and causes the aliens to spawn more frequently.

I have checked this.physics.world.fps and it is 60. I can also modify this.physics.world.timescale but then I would have to do a giant switch statement for every refresh rate.

Either I am missing an obvious solution or my global.gameTick method is not an effective way to accomplish this task.

This is what I have in my config so far

let config = {
    type: Phaser.AUTO,
    backgroundColor: "#000",
    scale: {
        parent: "game",
        mode: Phaser.Scale.FIT,
        width: 1900,
        height: 600,
    },
    physics: {
        default: "arcade",
        arcade: {
            debug: true,
            fps: 60 // doesn't fix update frequency
        },
        fps: { // not sure if this is even doing anything
            max: 60,
            min: 20,
            target: 60,
        }
    },
    pixelArt: true,
};

Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>