Skip to content

Commit

Permalink
Stabilizing time
Browse files Browse the repository at this point in the history
  • Loading branch information
ftripier committed Aug 22, 2018
1 parent cd799e3 commit c120a72
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class Engine {
this.queue.push(cb);
}

run(time?: number) {
if (!time) {
time = performance.now();
run(time: number) {
if (!this.state.startTime) {
this.state.startTime = time;
}
this.state.dt = time - this.state.time;
Expand All @@ -69,4 +68,4 @@ const loop = (state: State, ctx: CanvasRenderingContext2D) => {
engine.nextFrame(loop);
};
engine.nextFrame(loop);
engine.run();
window.requestAnimationFrame(engine.run.bind(engine));

0 comments on commit c120a72

Please sign in to comment.