我对javascript有点陌生,在编写游戏时遇到了这个错误。这让我很难过,因为这个功能似乎与所有其他功能相同,但它不起作用。
function Game() {}
Game.prototype.loadGame = function(x) {
this.cvs=document.getElementById(x);
this.cvs.height=480;
this.cvs.width=640;
this.sprites=[];
this.ctx=cvs.getContext("2d");
};
Game.prototype.update = function() {
console.log("u");
};
Game.prototype.draw = function() {
this.drawCircle(320, 240, 10, "green")
};
Game.prototype.drawCircle = function(centerX, centerY, radius, color) {
this.ctx.beginPath();
this.ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
this.ctx.fillStyle = color;
this.ctx.fill();
};
Game.prototype.tick = function() {
this.update();
this.draw();
};
Game.prototype.Init = function() {
fps=60
this.loadGame("cvs");
setInterval(this.tick, (1/fps)*1000);
};
g = new Game();
g.Init();
我得到错误:Uncaught TypeError: Object [object global] has no method 'update'
关于如何解决这个问题的任何想法?