fix: use Phaser shutdown event for listener cleanup

Phaser's game.destroy() calls shutdown() on scenes, not destroy().
The old destroy() override was never called, causing stale event
listeners to persist and throw errors in React StrictMode.
This commit is contained in:
tiennm99 committed 2026-04-07 22:00:15 +07:00
1 parent e6ccd6583c
commit 2c831040f0
1 file changed
+11 -1
+11 -1
View File
@@ -41,6 +41,15 @@ export class GameScene extends Phaser.Scene {
this.shuffleHandler = () => this.handleShuffle();
this.stateManager.on("hint", this.hintHandler);
this.stateManager.on("shuffle", this.shuffleHandler);
// Clean up listeners on scene shutdown (called by game.destroy)
this.events.on("shutdown", () => {
if (this.timerEvent) {
this.timerEvent.destroy();
}
this.stateManager.off("hint", this.hintHandler);
this.stateManager.off("shuffle", this.shuffleHandler);
});
}
private renderBoard(): void {
@@ -313,9 +322,10 @@ export class GameScene extends Phaser.Scene {
this.renderBoard();
}
destroy(): void {
shutdown(): void {
if (this.timerEvent) {
this.timerEvent.destroy();
this.timerEvent = null;
}
if (this.stateManager) {
this.stateManager.off("hint", this.hintHandler);