Jump to content

Phaser Timer and Timed Event Stop on PC Clock Rollback


st0n3vn
 Share

Recommended Posts

Hello, I just encountered the following issue. In two different games I am using two ways of updating the game time shown in the UI - a timer and a timed event. I've just discovered that changing the PC's clock by -1 hour (say it's 10:00 AM, I roll it back to 9:00 AM) causes the updating to stop. This issue is not present if I roll the clock forward (from 10:00 AM to 11:00 AM). I found a way around this by using setInterval and clearInterval, but I'd like to know if a Phaser internal fix or workaround exists, or maybe if I need to do something differently. Here is the case when using a timer:

private startTimer(): void {
    this.gameTime = 0;

    this.timer = this.game.time.create();
    this.timer.loop(Phaser.Timer.SECOND, () => {
        this.updateTime();
    }, this);
    this.timer.start();
};

And here is the case when using a timed event in the second game:

this.timeElapsed = 0;

this.game.time.events.loop(Phaser.Timer.SECOND, () => {
    this.updateTimer();
}, this);

Both calls are made in the play state's create function. This is on a Windows 10 PC.

Link to comment
Share on other sites

7 hours ago, st0n3vn said:

I've just discovered that changing the PC's clock by -1 hour (say it's 10:00 AM, I roll it back to 9:00 AM) causes the updating to stop.

Have you tried waiting an hour?

I don't think even Daylight Savings Time will trigger this because Date.now is UTC based.

Link to comment
Share on other sites

I'm pretty sure what you're describing is the expected behavior, but if you definitely need to avoid it you can try

Phaser.Timer.prototype.start: function (delay) {

    if (this.running)
    {
        return;
    }

    this._started = window.performance.timing.navigationStart + (delay || 0);

    this.running = true;

    for (var i = 0; i < this.events.length; i++)
    {
        this.events[i].tick = this.events[i].delay + this._started;
    }

}

 

Link to comment
Share on other sites

Actually, autoadjustment for daylight saving time will only trigger this once per year since the issue is with rolling back a clock, not forward. However, a player can manually change their PC clock for some reason. Also, I haven't tried yet waiting for an hour because a standard full session in these games will most likely continue not more than 30 minutes before starting over. I will try out what you suggested, thanks a lot!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...