Class Engine

The Engine class is the central point for creating and managing your game state. Add entities and systems to the engine, and fetch families of nodes from the engine.

Hierarchy

  • Engine

Constructors

Properties

FamilyClass: Class<Family<any>> = ComponentMatchingFamily

The class used to manage node lists. In most cases the default class is sufficient but it is exposed here so advanced developers can choose to create and use a different implementation.

The class must implement the Family interface.

updateComplete: Signal<[]>

Dispatched when the update loop ends. If you want to add and remove systems from the engine it is usually best not to do so during the update loop. To avoid this you can listen for this signal and make the change when the signal is dispatched.

updating: boolean = false

Indicates if the engine is currently in its update loop.

Accessors

Methods

  • Add an entity to the engine.

    Parameters

    • entity: Entity

      The entity to add.

    Returns void

  • Add a system to the engine, and set its priority for the order in which the systems are updated by the engine update loop.

    The priority dictates the order in which the systems are updated by the engine update loop. Lower numbers for priority are updated first. i.e. a priority of 1 is updated before a priority of 2.

    Parameters

    • system: System

      The system to add to the engine.

    • priority: number

      The priority for updating the systems during the engine loop. A lower number means the system is updated sooner.

    Returns void

  • Get an entity based n its name.

    Parameters

    • name: string

      The name of the entity

    Returns null | Entity

    The entity, or null if no entity with that name exists on the engine

  • Get a collection of nodes from the engine, based on the type of the node required.

    The engine will create the appropriate NodeList if it doesn't already exist and will keep its contents up to date as entities are added to and removed from the engine.

    If a NodeList is no longer required, release it with the releaseNodeList method.

    Type Parameters

    Parameters

    • nodeClass: NodeClass<TNode>

      The type of node required.

    Returns NodeList<TNode>

    A linked list of all nodes of this type from all entities in the engine.

  • Get the system instance of a particular type from within the engine.

    Type Parameters

    Parameters

    • type: Class<TSystem>

      The type of system

    Returns null | TSystem

    The instance of the system type that is in the engine, or null if no systems of this type are in the engine.

  • If a NodeList is no longer required, this method will stop the engine updating the list and will release all references to the list within the framework classes, enabling it to be garbage collected.

    It is not essential to release a list, but releasing it will free up memory and processor resources.

    Type Parameters

    Parameters

    • nodeClass: NodeClass<TNode>

      The type of the node class if the list to be released.

    Returns void

  • Remove all entities from the engine.

    Returns void

  • Remove an entity from the engine.

    Parameters

    • entity: Entity

      The entity to remove.

    Returns void

  • Remove a system from the engine.

    Parameters

    • system: System

      The system to remove from the engine.

    Returns void

  • Update the engine. This causes the engine update loop to run, calling update on all the systems in the engine.

    The package net.richardlord.ash.tick contains classes that can be used to provide a steady or variable tick that calls this update method.

    Parameters

    • time: number

    Returns void

    Time

    The duration, in seconds, of this update step.

Generated using TypeDoc