Constructor
new Timer(engine)
Examples
import { Engine, Timer } from 'jecs';
const engine = new Engine();
const timer = new Timer(engine);
engine.system('mySystem', ['myComponent'], (entity, { myComponent }) => {
const delta = timer.getTime().delta;
// Do your magic with delta time!
// ...
});
// Object returned by getTime() has this structure:
{
ticks, // Number of ticks (frames)
start, // Initial time (milliseconds since the EPOCH)
now, // Current time (milliseconds since the EPOCH)
total, // Total execution time (milliseconds)
delta // Delta time from prev tick (milliseconds)
}
Parameters:
Name | Type | Description |
---|---|---|
engine |
Engine | Engine instance this Timer will belong to |
Methods
getEntity() → {Entity}
Returns the entity used by this timer
Returns:
The timer entity
- Type
- Entity
getSystem() → {System}
Returns the system used by this timer
Returns:
The timer system
- Type
- System
getTime() → {Object}
Returns the time component
Example
The time object contains these properties:<br/>
<table>
<tr><th>start</td><td>initial time</td>
<tr><th>total</td><td>total execution time</td>
<tr><th>prev</td><td>previous frame absolute time</td>
<tr><th>delta</td><td>delta time from prev tick</td>
</table>
Returns:
A time component object
- Type
- Object
reset()
Reset all timing values to 0