[name]

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.

Import

[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';

Code Example

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 ); }

Examples

[example:webgl_morphtargets_sphere WebGL / morphtargets / sphere]

Constructor

Timer()

Methods

[method:Number getDelta]()

Returns the time delta in seconds.

[method:Number getElapsed]()

Returns the elapsed time in seconds.

[method:this setTimescale]( [param:Number timescale] )

Sets a time scale that scales the time delta in [page:.update]().

[method:this reset]()

Resets the time computation for the current simulation step.

[method:this dispose]()

Can be used to free all internal resources. Usually called when the timer instance isn't required anymore.

[method:this update]( [param:Number timestamp] )

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]()).

Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/misc/Timer.js examples/jsm/misc/Timer.js]