javascript – 在为phaser游戏添加requirejs后没有调用Typescript window.onload
作者:互联网
我正在尝试用phaser和Typescript制作游戏.我按照here的说明进行操作.当我尝试使用AMD和requirejs模块化我的代码时出现问题
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Resonate</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="phaser.js"></script>
<script src="http://requirejs.org/docs/release/2.1.20/minified/require.js" data-main="app"></script>
</head>
<body>
<h1>RESONATE</h1>
<div id="content"></div>
</body>
</html>
Player.ts
export class Player {
color: string;
constructor() {
this.color = "#0000ff";
}
}
app.ts
import player = require("Player");
class PhaserDemo {
game: Phaser.Game;
constructor() {
this.game = new Phaser.Game(800, 600, Phaser.WEBGL, 'content', { preload: this.preload, create: this.create });
}
preload() {
this.game.load.image('phaser_run', 'run.png');
}
create() {
console.log("Before");
var p = new player.Player();
this.game.stage.backgroundColor = p.color;
}
}
window.onload = () => {
console.log("ONLOAD");
var game = new PhaserDemo();
};
现在,当我加载它时,window.onload永远不会被调用,我试着跟随
window.onload not calling function
对于Javascript解决方案,但我不能让它在打字稿中工作.
这里也是生成的Javascript,如果你想看看https://gist.github.com/koreus7/06bee4a30d22bdc76d62
解决方法:
for the Javascript solution but I can’t get it to work in typescript.
基本上如果窗口已经加载附加到window.onload将不会调用附加的函数.
检查document.readyState ===“完成”.或者使用类似jquery ready的东西:https://api.jquery.com/ready/
标签:javascript,typescript,requirejs,phaser-framework,js-amd 来源: https://codeday.me/bug/20190628/1315684.html