have some time logic in the refresh
This commit is contained in:
parent
ed2c7db811
commit
09d6d5679c
2 changed files with 21 additions and 2 deletions
12
js/Env.js
12
js/Env.js
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
|
11
js/main.js
11
js/main.js
|
@ -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();
|
||||
|
|
Reference in a new issue