我想用Jvascript製作遊戲引擎。到目前爲止,我有:從對象內部調用setInterval Javascript?
function gameEngine() {
this.canvas = $('canvas')[0];
this.ctx = this.canvas.getContext('2d');
this.framerate = 20;
this.resetCanvas = function() {
this.ctx.fillStyle = 'red';
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
};
this.loop = function() {
this.resetCanvas();
};
this.run = function() {
setInterval(this.loop, this.framerate);
};
}
new gameEngine();
但畫布沒有顯示;爲什麼?
感謝您的鏈接,這已經幫助了很多:)將盡我所能接受! – Griff 2013-02-25 04:16:40
你的'或者使用閉包:'部分是錯的 – Musa 2013-02-25 04:19:51
我不能接受我有3分鐘;) – Griff 2013-02-25 04:20:53