fix: resetting methods

This commit is contained in:
2026-04-04 14:13:41 +08:00
parent 5fd2c3d208
commit 951fbc7045
2 changed files with 38 additions and 13 deletions
+24 -11
View File
@@ -32,6 +32,9 @@ export class GameScene extends GameHostScene<TicTacToeState> {
const winner = this.state.winner;
if (winner) {
this.showWinner(winner);
} else if (this.winnerOverlay) {
this.winnerOverlay.destroy();
this.winnerOverlay = undefined;
}
});
@@ -121,16 +124,20 @@ export class GameScene extends GameHostScene<TicTacToeState> {
const text = winner === 'draw' ? "It's a draw!" : `${winner} wins!`;
this.winnerOverlay.add(
this.add.rectangle(
BOARD_OFFSET.x + (BOARD_SIZE * CELL_SIZE) / 2,
BOARD_OFFSET.y + (BOARD_SIZE * CELL_SIZE) / 2,
BOARD_SIZE * CELL_SIZE,
BOARD_SIZE * CELL_SIZE,
0x000000,
0.6,
),
);
const bg = this.add.rectangle(
BOARD_OFFSET.x + (BOARD_SIZE * CELL_SIZE) / 2,
BOARD_OFFSET.y + (BOARD_SIZE * CELL_SIZE) / 2,
BOARD_SIZE * CELL_SIZE,
BOARD_SIZE * CELL_SIZE,
0x000000,
0.6,
).setInteractive({ useHandCursor: true });
bg.on('pointerdown', () => {
this.gameHost.setup('setup');
});
this.winnerOverlay.add(bg);
const winText = this.add.text(
BOARD_OFFSET.x + (BOARD_SIZE * CELL_SIZE) / 2,
@@ -196,6 +203,12 @@ class TicTacToePartSpawner implements Spawner<TicTacToePart, Phaser.GameObjects.
}
onDespawn(obj: Phaser.GameObjects.Text) {
obj.removedFromScene();
this.scene.tweens.add({
targets: obj,
alpha: 0,
duration: 200,
ease: 'Back.easeIn',
onComplete: () => obj.destroy(),
});
}
}