I feel like I've hit a wall with this problem... does anyone have any insight on what might be causing it to fail?
The goal is to use a text element as a button in my game, but whenever I launch it, all I see is a black screen and an error message.
Below is the TypeScript code for reference, excluding the window.onload
handler that initializes the MyGame class:
class MyGame {
game: Phaser.Game;
textStyle: object = { font: "Ubuntu", fill: "black", align: "center" };
constructor() {
this.game = new Phaser.Game(800, 640, Phaser.AUTO, 'content', { preload: this.preload, create: this.create, update: this.update });
}
preload() { }
create() {
this.game.stage.backgroundColor = "#eee";
let buttonPlay = this.game.add.text(this.game.world.centerX, this.game.world.centerY, "play", this.textStyle);
buttonPlay.anchor.setTo(0.5);
buttonPlay.inputEnabled = true;
buttonPlay.events.onInputUp.add(this.onPlay, this); //line 19
}
update() { }
onPlay() {
console.log("pressed play");
}
}
This is the specific error message I encounter:
Uncaught Error: Phaser.Signal: listener is a required param of add() and should be a Function.
at i.Signal.validateListener (phaser.min.js:3)
at i.Signal.add (phaser.min.js:3)
at Object.MyGame.create (app.ts:19)