fix: resetting methods
This commit is contained in:
@@ -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(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user