diff --git a/public/src/ui/Button.js b/public/src/ui/Button.js index 7025e27..a7b548c 100644 --- a/public/src/ui/Button.js +++ b/public/src/ui/Button.js @@ -46,13 +46,12 @@ export class Button extends Phaser.GameObjects.Container { this.add([this.bgRect, this.text]); - const bgHitArea = new Phaser.Geom.Rectangle(-hw, -hh, width, height); - const textHitArea = new Phaser.Geom.Rectangle(-hw, -hh, width, height); - const hitCb = Phaser.Geom.Rectangle.Contains; this.setSize(width, height); - this.setInteractive({ useHandCursor: true, hitArea: bgHitArea, hitAreaCallback: hitCb }); - this.bgRect.setInteractive({ hitArea: bgHitArea, hitAreaCallback: hitCb }); - this.text.setInteractive({ hitArea: textHitArea, hitAreaCallback: hitCb }); + this.setInteractive({ + useHandCursor: true, + hitArea: new Phaser.Geom.Rectangle(0, 0, width, height), + hitAreaCallback: Phaser.Geom.Rectangle.Contains, + }); const onOver = () => { if (isGhost) { @@ -70,14 +69,12 @@ export class Button extends Phaser.GameObjects.Container { const onDown = () => this.bgRect.setScale(0.97); const onUp = () => this.bgRect.setScale(1); - for (const target of [this, this.bgRect, this.text]) { - target.on('pointerover', onOver); - target.on('pointerout', onOut); - target.on('pointerdown', onDown); - target.on('pointerup', onUp); - target.on('pointerupoutside', onUp); - if (onClick) target.on('pointerup', onClick); - } + this.on('pointerover', onOver); + this.on('pointerout', onOut); + this.on('pointerdown', onDown); + this.on('pointerup', onUp); + this.on('pointerupoutside', onUp); + if (onClick) this.on('pointerup', onClick); scene.add.existing(this); }