Skip to content

Commit 302033b

Browse files
committed
Allow time-skewing of director clocks
1 parent 5d486e1 commit 302033b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Director.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ MathBox.Director = function (stage, script) {
1212

1313
this.step = 0;
1414
this.lastCommand = 0;
15+
16+
this.time = 0;
17+
this.lastTime = +new Date();
1518
};
1619

1720
MathBox.Director.prototype = {
@@ -25,6 +28,14 @@ MathBox.Director.prototype = {
2528
}
2629
if (reset || !this.clocks[step]) this.clocks[step] = +new Date();
2730
return (+new Date() - this.clocks[step]) * .001;
31+
32+
var now = +new Date();
33+
var delta = now - this.lastTime;
34+
this.time += delta * this.stage().speed();
35+
this.lastTime = now;
36+
37+
if (reset || !this.clocks[step]) this.clocks[step] = this.time;
38+
return (this.time - this.clocks[step]) * .001;
2839
},
2940

3041
/**

0 commit comments

Comments
 (0)