Button Fix
This commit is contained in:
parent
e171be7c10
commit
d9bf0432a6
|
|
@ -46,13 +46,12 @@ export class Button extends Phaser.GameObjects.Container {
|
||||||
|
|
||||||
this.add([this.bgRect, this.text]);
|
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.setSize(width, height);
|
||||||
this.setInteractive({ useHandCursor: true, hitArea: bgHitArea, hitAreaCallback: hitCb });
|
this.setInteractive({
|
||||||
this.bgRect.setInteractive({ hitArea: bgHitArea, hitAreaCallback: hitCb });
|
useHandCursor: true,
|
||||||
this.text.setInteractive({ hitArea: textHitArea, hitAreaCallback: hitCb });
|
hitArea: new Phaser.Geom.Rectangle(0, 0, width, height),
|
||||||
|
hitAreaCallback: Phaser.Geom.Rectangle.Contains,
|
||||||
|
});
|
||||||
|
|
||||||
const onOver = () => {
|
const onOver = () => {
|
||||||
if (isGhost) {
|
if (isGhost) {
|
||||||
|
|
@ -70,14 +69,12 @@ export class Button extends Phaser.GameObjects.Container {
|
||||||
const onDown = () => this.bgRect.setScale(0.97);
|
const onDown = () => this.bgRect.setScale(0.97);
|
||||||
const onUp = () => this.bgRect.setScale(1);
|
const onUp = () => this.bgRect.setScale(1);
|
||||||
|
|
||||||
for (const target of [this, this.bgRect, this.text]) {
|
this.on('pointerover', onOver);
|
||||||
target.on('pointerover', onOver);
|
this.on('pointerout', onOut);
|
||||||
target.on('pointerout', onOut);
|
this.on('pointerdown', onDown);
|
||||||
target.on('pointerdown', onDown);
|
this.on('pointerup', onUp);
|
||||||
target.on('pointerup', onUp);
|
this.on('pointerupoutside', onUp);
|
||||||
target.on('pointerupoutside', onUp);
|
if (onClick) this.on('pointerup', onClick);
|
||||||
if (onClick) target.on('pointerup', onClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.add.existing(this);
|
scene.add.existing(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue