【发布时间】:2012-05-23 15:45:44
【问题描述】:
function airEngineJS (canvasArg, properties) {
this.canvas = (canvasArg == "undefined")? trace("Failed to set up canvas for airEngineJS") : canvasArg;
this.cameras = [];
this.displayObjects = [];
this.hudDisplayObjects = [];
this.fps = (properties == "undefined" || properties.fps == "undefined")? 30 : properties.fps;
if (properties == "undefined" || properties.autoinit == "undefined" || properties.autoinit == true){
this.keyboard = new keyboardJS();
this.keyboard.init();
this.cameras.push(new airCameraJS(this));
}
this.enterframe = setInterval(this.intervalCaller, 1000/this.fps);
trace("A new airEngineJS has been created");
}
airEngineJS.prototype = {
intervalCaller : function () {
this.mainLoop();
},
logic : function () {
for (var i = 0; i < this.displayObjects.length; ++i){
this.displayObjects[i].logic();
}
for (var j = 0; j < this.cameras.length; ++j){
this.cameras[j].logic();
}
},
render : function () {
for (var i = 0; i < this.cameras.length; ++i){
for (var j = 0; j < this.displayObjects.length; ++j){
this.displayObjects[j].renderOn(this.cameras[i]);
}
}
for (var i = 0; i < this.hudDisplayObjects.length; ++i){
this.hudDisplayObjects[i].renderOn(this.canvas);
}
},
mainLoop : function () {
this.logic();
this.render();
}
}
区间 [this.enterframe = setInterval(this.intervalCaller, 1000/this.fps);] 调用正确 (this.intervalCaller),但是 this 尝试在 DOM 中调用 (this.mainLoop())。
关于我应该如何做的任何建议? :(
【问题讨论】:
标签: javascript function scope this setinterval