Engine

Engine

The engine manages all entities and the main system loop. Adding new entities to the engine will automatically set them up to be watched by the registered systems.

Constructor

new Engine()

Example
#Creating a new engine.
const engine = new Engine({
    interval: 16,
});
Mixes In:
Parameters
Name Type Attributes Default Description
config.interval number <optional>
16 The number of milliseconds between executions.

Methods

addEntities(…entities) → {Engine}

Adds all specified entities to the engine.
Parameters
Name Type Attributes Description
entities entities <repeatable>
The entities.
Throws
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Returns
Itself
Type
Engine

addSystems(…systems) → {Engine}

Adds all specified systems to the engine.
Parameters
Name Type Attributes Description
systems System <repeatable>
The systems.
Throws
TypeError
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Returns
Itself
Type
Engine

getState() → {string}

Get the engine state.
Throws
ReferenceError
Will throw this error if invoked after being disposed.
Returns
The engine state.
Type
string

init() → {Promise}

Initializes the engine and all registered systems.
Fires:
  • Engine#event:initialize
Throws
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Error
Will throw this error when the engine is not capable of being initialized.
Returns
The engine initialization.
Type
Promise

removeEntities(…entitiesOrIds) → {Engine}

Removes all specified entities from the engine.
Parameters
Name Type Attributes Description
entitiesOrIds Entity | number <repeatable>
The entities or entity ids.
Throws
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Returns
Itself
Type
Engine

start() → {Promise}

Starts the engine loop.
Fires:
  • Engine#event:start
  • Engine#event:idle
  • Engine#event:stop
  • Engine#event:tick
Throws
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Error
Will throw this error when the engine is not capable of being started.
Returns
The engine start.
Type
Promise

stop() → {Promise}

Stops the engine loop.
Fires:
  • Engine#event:stop
Throws
ReferenceError
Will throw this error if invoked after the engine has been disposed.
Error
Will throw this error when the engine is not capable of being stopped.
Returns
The engine stop.
Type
Promise