Timer

timer~ Timer

The Timer class is a utility class. By creating a new instance of this class, you will be able to retrieve timings informations in your systems.

Constructor

new Timer(engine)

Source:
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}

Source:

Returns the entity used by this timer

Returns:

The timer entity

Type
Entity

getSystem() → {System}

Source:

Returns the system used by this timer

Returns:

The timer system

Type
System

getTime() → {Object}

Source:

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

Source:

Reset all timing values to 0