【发布时间】:2018-06-17 06:57:12
【问题描述】:
我一直在努力完成这项工作......有人知道它有什么问题吗?
我正在尝试将文本对象用作按钮,但游戏启动时黑屏并出现错误。
这是整个打字稿减去创建 MyGame 实例的 window.onload 处理程序。
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");
}
}
这是我得到的错误:
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)
【问题讨论】:
标签: typescript phaser-framework