Scene.stop() doesn't work although clearInterval

I’m creating an online game using Phaser and Socket.IO.

To synchronize the countdown timer between players, I’m using setInterval instead of Phaser’s built-in timer, as using the Phaser timer results in inconsistent rendering times depending on the player’s computer specs.

Despite being aware of the content discussed in this topic, where it’s mentioned to clear the interval before calling scene.stop(), I still encounter an issue where the display elements on the current screen remain visible after stopping the scene. And after that, when I refresh the page, the browser gets stuck in an infinite buffering loop to the point where it becomes unresponsive.

Is there anything else I should do?

I’ll attach the current code for this situation.


// parent scene

export default class OnlineBase extends Scene {
      ...
      create(callback) {
           socket.on('user_loaded') {
                 this.gameStartCallback();
           }

           socket.emit('game_update', {
                status: 'game_start',
               ingame_info: this.gameData.ingame_info,
               event: 'user_loaded',
            });
          this.gameStartCallback = callback

          this.interval = setInterval(() => {
               // time - 1 logic
          }, 1000)
      }
       
     onGameEnd () {
           clearInterval(...)
           socket.off(...)
         
           // it doesn't work
           this.scene.stop();
           this.scene.wake('home');
     }
}

// child scene

export default class OnlineGame extends OnlineBase {
       ...
       create() {
             super.create(() => this.start());
       }
}

I don’t think there should be a problem using Phaser’s timer’s on different devices. But I think if you want to truly synchronize them then you would decide on a start time on the server and count down to that.

Some possibilities:

  • The game froze after an error, before the scene could redraw
  • scene.stop() never got called
  • The scene is getting restarted
  • It’s a different scene showing the same contents