please help, I cant find out why this is throwing the error. I've tried everything I can think of, why is this.runLoop() defined and suddenly this.processInput() not, I'm trying to understand classes better and I finally thought I got it, I guess not
class Game {
constructor(teamSize){
this.cpu1 = new Array(teamSize-1);
this.cpu2 = new Array(teamSize);
this.run = -1;
this.init();
}
init(){
}
shutdown(){};
processInput = function(elapsed) {
console.log(elapsed);
}
updateGame(elapsed){}
generateOutput(elapsed){
}
runLoop(timestamp){
let last;
if(last === undefined){
last = timestamp;
}
let elapsed = timestamp - last;
this.processInput(elapsed);
this.updateGame(elapsed);
this.generateOutput(elapsed);
last = timestamp;
if(this.run == 1){
window.requestAnimationFrame(this.runLoop);
}
};
start(){
this.run *= -1;
if(this.run == 1){
window.requestAnimationFrame(this.runLoop);
}
}
};
var g = new Game(5);
g.start();
does the error have something to do with the window.requestAnimationFrame() does that become the object 'this' would be referring to?