【发布时间】:2016-02-21 00:20:02
【问题描述】:
我是 javascript/typescript 的新手,我正在尝试在使用 Phaser 构建一个简单的游戏时学习它。我一直在启动游戏实例:当我在 Phaser 网站上的第一个示例中创建它时,它会启动,但如果我在表单提交上调用的函数内创建游戏对象,它会启动但立即结束;这是代码:
index.html
<form class="well" onsubmit="submitForm()">
...
...
<button type="submit" class="btn btn-primary">Play</button>
</form>
app.ts
var game: SimpleGame;
function submitForm() {
console.log('Form submitted');
game = new SimpleGame();
}
game.ts
class SimpleGame {
constructor() {
this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'content',
{
preload: this.preload,
create: this.create,
update: this.update,
render: this.render
});
}
...
...
}
就像每次函数submitForm()返回时游戏对象都被销毁了。
【问题讨论】:
-
你能在 plnkr 或 jsfiddle 上重现错误吗?
标签: javascript typescript phaser-framework