Skip to content

Commit cdbbb45

Browse files
author
Sascha Braun
committed
add update deltaTime
1 parent 21129ab commit cdbbb45

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/components/Three.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class Three extends Vue {
2020

2121
private _app!: Application;
2222
private _animationFrame?: number;
23+
private _lastUpdate?: number;
2324

2425
public app() {
2526
return this._app;
@@ -67,13 +68,17 @@ export class Three extends Vue {
6768
public onActivate() {
6869
console.log("activate render loop");
6970
if (!this._animationFrame) {
71+
this._lastUpdate = Date.now();
7072
this.onRender();
7173
}
7274
}
7375

7476
public onRender() {
77+
const now = Date.now();
78+
const deltaTime = (now - this._lastUpdate!) * 0.001;
7579
this._animationFrame = requestAnimationFrame(this.onRender);
76-
this._app.update(0);
80+
this._app.update(deltaTime);
81+
this._lastUpdate = now;
7782
}
7883

7984
private onResize() {

src/core/Application.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ export class Application {
6464
public update(deltaTime: number) {
6565
const scene = this.sceneManager.active;
6666
const camera = this.cameraManager.main;
67-
if (this.renderer) {
68-
this.renderer.clearColor();
69-
this.inputs.update();
7067

71-
this._hooks.emit("update", deltaTime);
68+
this.inputs.update();
69+
this._hooks.emit("update", deltaTime);
7270

71+
if (this.renderer) {
72+
this.renderer.clearColor();
7373
if (scene && camera) {
7474
this.renderer.render(scene, camera);
7575
}

0 commit comments

Comments
 (0)