The EntityManager manages the entities and components.
It provides the necessary methods for reading and writing entities and components.

Constructors

Methods

  • Adds a component to the entity

    Type Parameters

    Parameters

    • entity: number

      The Entity to which the component will be added

    • componentType: ComponentType<T>

      The class of the component

    Returns T

    The instance of the component

    const spriteRenderer = entityManager.addComponent(entity, SpriteRenderer);
    
  • Adds an instance of a component to an entity

    Type Parameters

    Parameters

    • entity: number

      The Entity to which the component will be added

    • component: T

      The instance of the component

    Returns T

    The instance of the component

    const spriteRenderer = new SpriteRenderer();
    entityManager.addComponent(entity, spriteRenderer);
  • Creates multiple entities based on an array of component collections

    Parameters

    • componentsList: Component[][]

      An array of collections of component instances and component classes

    Returns number[]

    An array with the created entities, in the same order of the collections of components

    const parent =  [
    new Transform({position: new Vector2(100, 100)}),
    SpriteRenderer
    ];

    const child = [
    new Transform({parent: parent[0]}),
    SpriteRenderer
    ];

    const entity = entityManager.createEntities([parent, child]);
  • Creates an entity without component

    Returns number

    The created Entity

    const entity = entityManager.createEntity();
    
  • Creates an Entity based on a collection of Component instances and ComponentTypes

    Parameters

    Returns number

    The created Entity

    const entity = entityManager.createEntity([
    new Transform({position: new Vector2(100, 100)}),
    SpriteRenderer
    ]);
  • Disables a component instance

    Parameters

    Returns void

    entityManager.disableComponent(spriteRenderer);
    
  • Disables a component by its entity and type

    Type Parameters

    Parameters

    • entity: number

      The target entity

    • componentType: ComponentType<T>

      The component class

    Returns void

    entityManager.disableComponent(entity, SpriteRenderer);
    
  • Disable all Entities that have a component of the given type

    Parameters

    Returns void

    entityManager.disableEntitiesByComponent(SpriteRenderer);
    
  • Disables an Entity

    Parameters

    • entity: number

      The entity to be disabled

    Returns void

    entityManager.disableEntity(entity);
    
  • Enables a component instance

    Parameters

    Returns void

    entityManager.enableComponent(spriteRenderer);
    
  • Enables a component by its entity and type

    Type Parameters

    Parameters

    • entity: number

      The target entity

    • componentType: ComponentType<T>

      The component class

    Returns void

    entityManager.enableComponent(entity, SpriteRenderer);
    
  • Enable all Entities that have a component of the given type

    Parameters

    Returns void

    entityManager.enableEntitiesByComponent(SpriteRenderer);
    
  • Enables an Entity

    Parameters

    • entity: number

      The entity to be enabled

    Returns void

    entityManager.enableEntity(entity);
    
  • Returns the component of the given type belonging to the entity

    Type Parameters

    Parameters

    • entity: number

      The entity

    • componentType: ComponentType<T>

      The class of the component

    Returns T

    The instance of the component

    const spriteRenderer = entityManager.getComponent(entity, SpriteRenderer);
    
  • Returns all the component belonging to the entity

    Parameters

    • entity: number

      The entity

    Returns Component[]

    A collection of component instances

    const components = entityManager.getComponents(entity);
    
  • Searches for and returns an entity for the component instance

    Parameters

    Returns number

    The found Entity

    const entity = entityManager.getEntityForComponent(spriteRenderer);
    
  • Returns TRUE if the Entity has a component of the given type, otherwise it returns FALSE.

    Parameters

    Returns boolean

    boolean

    const hasSpriteRenderer = entityManager.hasComponent(entity, SpriteRenderer);
    
  • Returns TRUE if the component is enabled, otherwise it returns FALSE

    Parameters

    Returns boolean

    boolean

    entityManager.isComponentEnabled(spriteRenderer)
    
  • Returns TRUE if the component is enabled, otherwise it returns FALSE

    Type Parameters

    Parameters

    • entity: number

      The target entity

    • componentType: ComponentType<T>

      The component class

    Returns boolean

    boolean

    entityManager.isComponentEnabled(entity, SpriteRenderer)
    
  • If the Entity exists, returns TRUE, otherwise it returns FALSE

    Parameters

    • entity: number

    Returns boolean

    boolean

    const isEntity = entityManager.isEntity(entity);
    
  • If the Entity is enabled, returns TRUE, otherwise it returns FALSE

    Parameters

    • entity: number

      The entity to verify

    Returns boolean

    boolean

    const entityEnabled = entityManager.isEntityEnabled(entity);
    
  • Removes all Entities and all their Components

    Returns void

    entityManager.removeAllEntities();
    
  • Removes the component instance from its Entity

    Parameters

    Returns void

    entityManager.removeComponent(spriteRenderer)
    
  • Removes a component from the entity according to the given type

    Parameters

    Returns void

    entityManager.removeComponent(entity, SriteRenderer)
    
  • Removes an Entity and all its Components

    Parameters

    • entity: number

      The entity to remove

    Returns void

    entityManager.removeEntity(entity);
    
  • Performs a search for entities given a component type.
    This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.
    This search can be filtered by passing as a second argument an instance of SearchCriteria, which performs a match between the attributes of the component and the given value.
    The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.

    Type Parameters

    Parameters

    • componentType: ComponentType<T>

      The component class

    • Optionalcriteria: SearchCriteria

      The search criteria

    • includeDisabled: boolean = false

      TRUE to incluide disabled entities and components, FALSE otherwise

    Returns SearchResult<T>[]

    SearchResult

    const searchResult = entityManager.search(SpriteRenderer);
    searchResult.forEach(({component, entity}) => {
    // do something with the component and entity
    })
    const searchResult = entityManager.search(Enemy, {status: "alive"});
    searchResult.forEach(({component, entity}) => {
    // do something with the component and entity
    })
  • Performs an entity search given a collection of component types.
    The entities found must have an instance of all the given component types.
    This method returns a collection of Entities.

    Parameters

    Returns number[]

    A collection of entities

    const entities = entityManager.searchEntitiesByComponents([Transform, SpriteRenderer, Animator]);