As an exercise, I went through this tutorial, then attempted to create a version that puts everything into its own class to clean it up so I can add some of my own additions. The issue is that I am running into an error that doesn't seem to make any sense. (all the commented stuff is filled in on my end, but it didn't seem relevant to the question) Uncaught TypeError: Cannot read property 'lastRender' of null at loop (game-loop.js:13)
class GameLoop {
constructor(player, canvas) {
// Set other variables
this.lastRender = 0;
window.requestAnimationFrame(this.loop);
}
loop(timestamp) {
let progress = timestamp - this.lastRender; // This is ln. 13 in the actual program
this.update(progress);
this.draw();
this.lastRender = timestamp;
window.requestAnimationFrame(this.loop);
}
update(progress) {
// Update function
}
draw() {
// Draw function
}
}
Additionally when I remove the lastRender variable from the class, it stops giving me that error, but instead says Uncaught TypeError: Cannot read property 'update' of null at loop (game-loop.js:15)