fix(game): 修复召唤按钮第二次失效和实习生不攻击的Bug

This commit is contained in:
Cloud Bot
2026-03-21 09:00:43 +00:00
parent caf9c698c9
commit 27ba03260f
3 changed files with 11 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ export class HUD {
private scene: Phaser.Scene
private waveBtn: Phaser.GameObjects.Text | null = null
private waveBannerTimeout: (() => void) | null = null
private _onClick: (() => void) | null = null
constructor(scene: Phaser.Scene) {
this.scene = scene
@@ -22,6 +23,7 @@ export class HUD {
*/
createWaveButton(onClick: () => void): void {
if (this.waveBtn) this.waveBtn.destroy()
this._onClick = onClick // 保存引用,供 enableWaveButton 重新绑定
this.waveBtn = this.scene.add
.text(GAME_WIDTH - 160, HUD_HEIGHT + 20, '▶ 召唤下一波', {
@@ -58,6 +60,11 @@ export class HUD {
enableWaveButton(): void {
if (!this.waveBtn) return
this.waveBtn.setStyle({ color: '#A78BFA', backgroundColor: '#1e3a5f' })
// 重新绑定点击事件disableWaveButton 会 removeAllListeners
this.waveBtn.removeAllListeners('pointerdown')
if (this._onClick) {
this.waveBtn.on('pointerdown', () => this._onClick!())
}
}
/**