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());
}
}