有人可以向我解释为什么我会得到:
未捕获的类型错误:无法读取未定义 game.js:48 的属性“画布”
未捕获的类型错误:无法调用未定义 game.js:4 的方法“调整大小”
似乎由于某种原因 this.stage 超出了 start 函数的范围。
//index.js
var game;
function init()
{
game = new Game(document.getElementById('canvas'));
}
function resize()
{
game.resize();
}
_
//game.js
function Game(canvas)
{
this.canvas = canvas;
this.stage = null;
this.loader = null;
this.scaleCanvas();
this.initCreateJS();
this.loadAssets();
}
Game.prototype =
{
resize: function()
{
this.scaleCanvas(this.canvas);
this.level.resize(this.canvas.width, this.canvas.height);
this.stage.update();
},
scaleCanvas: function()
{
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
},
initCreateJS: function()
{
this.stage = new createjs.Stage(this.canvas);
createjs.Ticker.setFPS(30);
this.stage.enableMouseOver(10);
if(createjs.Touch.isSupported())
{
createjs.Touch.enable(this.stage);
}
},
loadAssets: function()
{
manifest = [
{src:"base.png", id:"base"},
{src:"logo.png", id:"logo"}
];
this.loader = new Loader(manifest, this.start);
},
start: function()
{
this.level = new Level(4,4,this.stage.canvas.width,game.stage.canvas.height);
this.level.randomLevel();
this.level.print();
game.stage.addChild(this.level);
game.stage.update();
}
};