For a game engine I am making with three js I need to put it into a class. But now when I put it into the class everything works except when I tell the requestAnimateFrame() to link to itself it says "BEngine.js:19 Uncaught TypeError: Cannot read properties of undefined (reading 'animate')".
export class BEngine
{
constructor(doc){
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
this.renderer = new THREE.WebGLRenderer({ antialias: true });
this.renderer.setSize(window.innerWidth, window.innerHeight);
doc.body.appendChild(this.renderer.domElement);
window.addEventListener("resize", this.onWindowResize, false);
}
animate()
{
requestAnimationFrame(this.animate);
this.renderer.render(this.scene, this.camera);
}
onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
}