Hello,
I working with the Zenva Tutorials and I have ran into an issue.
class UiButton extends Phaser.GameObjects.Container {
constructor(scene, x, y, key, hoverKey, text, targetCallback){
super(scene, x, y);
this.scene = scene; // the scene this container will be added to
this.x = x; // x pos
this.y = y; // y pos
this.key = key; // BG image of button
this.hoverKey = hoverKey; // image displays when hovered
this.text = text; // text displayed on button
this.targetCallback = targetCallback; // the callback function that will be called when clicked
this.createButton(); // Creates UI Button
this.scene.add.existing(this); // adds this container to our Phaser Scene
}
createButton() {
//create Play Game Button
this.button = this.add.image(0, 0, "button1");
//make button interactive
this.button.setInteractive();
//scale the button
this.button.setScale(1.4);
//create button text
this.buttonText = this.add.text(0, 0, this.text, {fontSize: "26px", fill: "#fff"});
//center text in ui button
Phaser.Display.Align.In.Center(this.buttonText, this.button);
//add the two game objects to container
this.add(this.button);
this.add(this.buttonText);
//Listen for events
this.button.on("pointerdown", () => {
this.targetCallback();
});
this.button.on("pointerover", () => {
this.button.setTexture(this.hoverKey);
});
this.button.on("pointerout", () => {
this.button.setTexture(this.key);
});
}
}
Any help would be appreciated!
Cheers