have some time logic in the refresh

This commit is contained in:
Mylloon 2022-11-24 18:41:17 +01:00
parent ed2c7db811
commit 09d6d5679c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 21 additions and 2 deletions

View file

@ -42,6 +42,9 @@ export class Env {
light.position.set(2, 1, 4);
light.castShadow = true;
this.scene.add(light);
// Clock
this.clock = new THREE.Clock();
}
/**
@ -100,4 +103,13 @@ export class Env {
* @returns
*/
render = () => this.renderer.render(this.scene, this.camera);
/**
* Update the game logic
*/
update = () => {
console.log(s);
this.animate();
this.render();
};
}

View file

@ -22,10 +22,17 @@ const main = () => {
addEventListener("keypress", joueur.controlUser);
/**
* Run the game
*/
const animate = () => {
const delta = env.clock.getDelta();
const ticks = Math.round(delta / (1 / 120));
for (let i = 0; i < ticks; i++) {
env.update();
}
requestAnimationFrame(animate);
env.animate();
env.render();
};
animate();