I'm a little bit new to javascript and I came across this error while writing a game. It stumps me since this function seems the same as all of the other functions, yet, it doesn't work.
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();
I get the error: Uncaught TypeError: Object [object global] has no method 'update'
Any idea as to how to fix this?