【发布时间】:2019-02-04 18:18:03
【问题描述】:
我一直在关注this tutorial 的移相器,但我无法运行第 4 项中的代码。我完全复制了它,没有进行任何修改(请参阅下文,如果您还没有看过教程),但我遇到了错误。
new Phaser.Game(800, 600, Phaser.AUTO, 'content', { preload: this.preload, create: this.create }); 行给了我错误“[ts] 预期 0-1 参数,得到 5”,而且我还被告知属性“加载”、“添加”和“世界”不t 存在于“游戏”类型中。
在尝试编译时,我得到了这个响应。
TSError: ⨯ Unable to compile TypeScript:
app.ts(4,25): error TS2304: Cannot find name 'Phaser'.
app.ts(4,47): error TS2304: Cannot find name 'Phaser'.
app.ts(7,11): error TS2503: Cannot find namespace 'Phaser'.
at createTSError (C:\Users\Username\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:261:12)
at getOutput (C:\Users\Username\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:367:40)
at Object.compile (C:\Users\Username\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:558:11)
at Module.m._compile (C:\Users\Username\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:439:43)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\Username\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:442:12)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
我现在的 app.ts:
class SimpleGame {
constructor() {
this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'content', { preload: this.preload, create: this.create });
}
game: Phaser.Game;
preload() {
this.game.load.image('logo', 'phaser2.png');
}
create() {
var logo = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo');
logo.anchor.setTo(0.5, 0.5);
}
}
window.onload = () => {
var game = new SimpleGame();
};
任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: typescript visual-studio-code phaser-framework