File tree 2 files changed +14
-7
lines changed
2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 11
11
< h1 > [name]</ h1 >
12
12
13
13
< p class ="desc ">
14
- This class is an alternative to [page:Clock] with a different API design and behavior
14
+ This class is an alternative to [page:Clock] with a different API design and behavior.
15
15
The goal is to avoid the conceptual flaws that became apparent in [page:Clock] over time.
16
16
17
17
< ul >
@@ -37,11 +37,12 @@ <h2>Code Example</h2>
37
37
< code >
38
38
const timer = new Timer();
39
39
40
- function animate() {
40
+ function animate( timestamp ) {
41
41
42
42
requestAnimationFrame( animate );
43
-
44
- timer.update();
43
+
44
+ // timestamp is optional
45
+ timer.update( timestamp );
45
46
46
47
const delta = timer.getDelta();
47
48
@@ -109,8 +110,14 @@ <h3>[method:this setTimescale]( [param:Number timescale] )</h3>
109
110
Sets a time scale that scales the time delta in [page:.update]().
110
111
</ p >
111
112
112
- < h3 > [method:this update]()</ h3 >
113
+ < h3 > [method:this update]( [param:Number timestamp] )</ h3 >
113
114
< p >
115
+ timestamp -- (optional) The current time in milliseconds. Can be obtained from the
116
+ [link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]
117
+ callback argument. If not provided, the current time will be determined with
118
+ [link:https://developer.mozilla.org/en-US/docs/Web/API/Performance/now performance.now]. Please note that this
119
+ parameter has no effect when using a fixed time delta.< br /> < br />
120
+
114
121
Updates the internal state of the timer. This method should be called once per simulation step
115
122
and before you perform queries against the timer (e.g. via [page:.getDelta]()).
116
123
</ p >
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ class Timer {
104
104
105
105
}
106
106
107
- update ( ) {
107
+ update ( timestamp ) {
108
108
109
109
if ( this . _useFixedDelta === true ) {
110
110
@@ -113,7 +113,7 @@ class Timer {
113
113
} else {
114
114
115
115
this . _previousTime = this . _currentTime ;
116
- this . _currentTime = now ( ) - this . _startTime ;
116
+ this . _currentTime = ( timestamp !== undefined ? timestamp : now ( ) ) - this . _startTime ;
117
117
118
118
this . _delta = this . _currentTime - this . _previousTime ;
119
119
You can’t perform that action at this time.
0 commit comments