This class is an alternative to [page:Clock] with a different API design and behavior. The goal is to avoid the conceptual flaws that became apparent in [page:Clock] over time.
[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].
import { Timer } from 'three/addons/misc/Timer.js';
const timer = new Timer();
function animate( timestamp ) {
requestAnimationFrame( animate );
// timestamp is optional
timer.update( timestamp );
const delta = timer.getDelta();
// do something with delta
renderer.render( scene, camera );
}
[example:webgl_morphtargets_sphere WebGL / morphtargets / sphere]
Connects the timer to the given document. Calling this method is not mandatory to use the timer but enables the usage of the Page Visibility API to avoid large time delta values.
Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
Returns the time delta in seconds.
Returns the elapsed time in seconds.
Sets a time scale that scales the time delta in [page:.update]().
Resets the time computation for the current simulation step.
Can be used to free all internal resources. Usually called when the timer instance isn't required anymore.
timestamp -- (optional) The current time in milliseconds. Can be obtained from the
[link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]
callback argument. If not provided, the current time will be determined with
[link:https://developer.mozilla.org/en-US/docs/Web/API/Performance/now performance.now].
Updates the internal state of the timer. This method should be called once per simulation step
and before you perform queries against the timer (e.g. via [page:.getDelta]()).
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/misc/Timer.js examples/jsm/misc/Timer.js]