Hierarchy

  • IEngine

Properties

CameraEntity: Entity

Camera entity of current player.

PlayerEntity: Entity

The current player entity

RootEntity: Entity

Refer to the root of the scene, all Transforms without a parent are parenting with RootEntity.

_id: number

Methods

  • Increment the used entity counter and return the next one.

    Returns

    the next entity unused

    Returns Entity

  • Add the system to the engine. It will be called every tick updated.

    Example

    function mySystem(dt: number) {
    const entitiesWithMeshRenderer = engine.getEntitiesWith(MeshRenderer, Transform)
    for (const [entity, _meshRenderer, _transform] of engine.getEntitiesWith(MeshRenderer, Transform)) {
    // do stuffs
    }
    }
    engine.addSystem(mySystem, 10)

    Parameters

    • system: SystemFn

      function that receives the delta time between last tick and current one.

    • Optional priority: number

      a number with the priority, big number are called before smaller ones

    • Optional name: string

      optional: a unique name to identify it

    Returns void

  • Alpha

    Parameters

    • transport: Transport

      transport which changes its onmessage to process CRDT messages

    Returns void

  • Define a component and add it to the engine.

    Returns

    The component definition

    Example

    const CustomComponent = engine.defineComponent("my-scene::custom-name", {
    id: Schemas.Int,
    name: Schemas.String
    })

    Type Parameters

    Parameters

    • componentName: string

      unique name to identify the component, a hash is calculated for it, it will fail if the hash has collisions.

    • spec: T

      An object with schema fields

    • Optional constructorDefault: Partial<MapResult<T>>

      the initial value prefilled when a component is created without a value

    Returns MapComponentDefinition<MapResult<T>>

  • Define a component and add it to the engine.

    Returns

    The component definition

    Example

    const StateComponentId = 10023
    const StateComponent = engine.defineComponentFromSchema("my-lib::VisibleComponent", Schemas.Bool)

    Type Parameters

    • T

    Parameters

    • componentName: string

      unique name to identify the component, a hash is calculated for it, it will fail if the hash has collisions.

    • spec: ISchema<T>

      An object with schema fields

    Returns LastWriteWinElementSetComponentDefinition<T>

  • Defines a value set component.

    Returns

    The component definition

    Example

    const StateComponentId = 10023
    const StateComponent = engine.defineValueSetComponentFromSchema("my-lib::VisibleComponent", Schemas.Int)

    Type Parameters

    • T

    Parameters

    • componentName: string

      unique name to identify the component, a hash is calculated for it, it will fail if the hash has collisions.

    • spec: ISchema<T>

      An object with schema fields

    • options: ValueSetOptions<T>

    Returns GrowOnlyValueSetComponentDefinition<T>

  • Get the component definition from the component id.

    Returns

    the component definition, throw an error if it doesn't exist

    const StateComponentId = 10023
    const StateComponent = engine.getComponent(StateComponentId)

    Type Parameters

    • T

    Parameters

    • componentId: string | number

      component number or name used to identify the component descriptor

    Returns ComponentDefinition<T>

  • Get the component definition from the component id.

    Returns

    the component definition or null if its not founded

    const StateComponentId = 10023
    const StateComponent = engine.getComponent(StateComponentId)

    Type Parameters

    • T

    Parameters

    • componentId: string | number

      component number or name used to identify the component descriptor

    Returns null | ComponentDefinition<T>

  • Get a iterator of entities that has all the component requested.

    Returns

    An iterator of an array with the [entity, component1, component2, ...]

    Example:

    for (const [entity, meshRenderer, transform] of engine.getEntitiesWith(MeshRenderer, Transform)) {
    // the properties of meshRenderer and transform are read only
    }

    Type Parameters

    Parameters

    • Rest ...components: T

      a list of component definitions

    Returns Iterable<[Entity, ...ReadonlyComponentSchema<T>[]]>

  • Alpha

    Search for the entity that matches de label string defined in the editor.

    Parameters

    • label: string

    Returns null | Entity

  • Check the state of an entityin the engine

    Returns

    EntityState enum

    Parameters

    • entity: Entity

      the entity to validate

    Returns EntityState

  • Registers a custom component definition.

    Type Parameters

    • T

    Parameters

    • componentName: string

      unique name to identify the component, a hash is calculated for it, it will fail if the hash has collisions.

    • componentDefinition: ComponentDefinition<T>

      The component definition

    Returns ComponentDefinition<T>

  • Parameters

    • componentId: string | number

      component number or name

    Returns void

  • Remove all components of an entity

    Parameters

    Returns void

  • Remove all components of each entity in the tree made with Transform parenting

    Parameters

    • entity: Entity

      the root entity of the tree

    Returns void

  • Remove a system from the engine.

    Returns

    if it was found and removed

    Parameters

    • selector: string | SystemFn

      the function or the unique name to identify

    Returns boolean

  • Seals the engine components. It is used to clearly define the scope of the components that will be available to this engine and to run optimizations.

    Returns void

  • Parameters

    • deltaTime: number

      deltaTime in seconds

    Returns Promise<void>