I foolishly thought that a good way to get into javascript and making games would be to make a game in javascript. I used this as a tutorial, but I'm an OOP programmer, so I thought I would make it OOP. In brief my new version is this:
function Game(){this.whatever = that;...};
Game.prototype.reset = function() {...};
Game.prototype.update = function(dt) {...};
Game.prototype.render = function() {...};
Game.prototype.main = function() {
var now = Date.now();
var delta = now-this.then;
this.update(delta/1000);
this.render();
this.then = now;
requestAnimationFrame(this.main);
};
var g = new Game();
g.reset();
g.main();
I can't figure out what's wrong, but I get this error:
TypeError: this.update is not a function
I added the console.log for this and it shows me that it runs main twice on the correct object, and then suddenly on the third time this
is the window. What am I doing wrong?