import * as Phaser from "phaser"; class GameButton { group: Phaser.GameObjects.Group | null = null; sprite: Phaser.GameObjects.Sprite | null = null; constructor(scene: Phaser.Scene, x: number, y: number, text: string) { const textObject = new Phaser.GameObjects.Text(scene, x, y, text, { color: 'black', }) textObject.setOrigin(.5, .5) const topLeft = new Phaser.GameObjects.Image(scene, x, y, 'button-bg', 0) const top = new Phaser.GameObjects.Image(scene, x, y, 'button-bg', 1) const topRight = new Phaser.GameObjects.Image(scene, x, y, 'button-bg', 2) // bgObject.setScale(((textObject.width + 40) / 48), ((textObject.height + 40) / 48)) //bgObject.setInteractive(); //bgObject.on('pointerover', () => { //}) const buttonGroup = new Phaser.GameObjects.Group(scene) buttonGroup.add(textObject) buttonGroup.add(topLeft) buttonGroup.add(top) buttonGroup.add(topRight) this.group = buttonGroup scene.add.existing(topLeft) scene.add.existing(topRight) scene.add.existing(textObject) scene.add.existing(buttonGroup) console.log(textObject.width, textObject.height) } onEvent(eventName: any, fn: any) { this.sprite?.on(eventName, fn) } moveTo(x: number, y: number) { this.group?.setXY(x, y) } } export default GameButton;