Adds a component to the entity
The Entity to which the component will be added
The class of the component
The instance of the component
Adds an instance of a component to an entity
The Entity to which the component will be added
The instance of the component
The instance of the component
Creates an entity without component
The created Entity
Creates an Entity with the given components.
Since the components are not cloned, the collection of components must not be reused.
A collection of component instances and component classes
Optional
parent: numberThe parent entity (optional)
The created Entity
Creates an Entity based on an Archetype.
Since the components are cloned, the archetype can be reused to create multiple entities.
The archetype to create the entity from
Optional
parent: numberThe parent entity (optional)
The created Entity
Disables a component instance
The component instance
Disables a component by its entity and type
The target entity
The component class
Disable all Entities that have a component of the given type
The class of the component
Disables an entity.
The entity's components will not be included in the search
results
and therefore will not be processed by their respective systems
(the engine built-in systems use the search
method to retrieve the entities).
If the entity has children, they will also be disabled.
The entity to be disabled
Enables a component instance
The component instance
Enables a component by its entity and type
The target entity
The component class
Enable all Entities that have a component of the given type
The class of the component
Enables an Entity.
The entity's components will be included in the search
results
and therefore will be processed by their respective systems
(the engine built-in systems use the search
method to retrieve the entities).
If the entity has children, they will also be enabled, except for those that have been manually disabled.
The entity to be enabled
Searches for and returns an entity for the component instance
The component instance
The found Entity
Returns TRUE if the Entity has a component of the given type, otherwise it returns FALSE.
The entity to verify
The class of the component
boolean
Returns TRUE if the component is enabled, otherwise it returns FALSE
The component instance
boolean
Returns TRUE if the component is enabled, otherwise it returns FALSE
The target entity
The component class
boolean
Removes all Entities and all their Components
Optional
preserveComponentType: ComponentTypeOptional component type to preserve entities that have this component
Removes the component instance from its Entity
The component instance
Removes a component from the entity according to the given type
The target entity
The component class
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 a filter function.
The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
The component class
Optional
filter: ((component: T, entity?: number) => boolean)The filter function
Optional
entity: numberOptional
includeDisabled: booleanTRUE to incluide disabled entities and components. Default is FALSE.
SearchResult
const searchResult = entityManager.search(SpriteRenderer);
searchResult.forEach(({component, entity}) => {
// do something with the component and entity
})
const searchResult = entityManager.search(Enemy, (component) => component.status === "alive");
searchResult.forEach(({component, entity}) => {
// do something with the component and entity
})
// include disabled entities and components
const searchResult = entityManager.search(Enemy, (component) => component.status === "dead", true);
searchResult.forEach(({component, entity}) => {
// do something with the component and 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.
The second argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
The component class
Optional
includeDisabled: booleanTRUE to incluide disabled entities and components. Default is FALSE.
SearchResult
const searchResult = entityManager.search(SpriteRenderer);
searchResult.forEach(({component, entity}) => {
// do something with the component and entity
})
// include disabled entities and components
const searchResult = entityManager.search(Enemy, true);
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.
A collection of component classes
A collection of entities
Performs a search for entities that have a component of the given type and are children of the parent entity.
This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.
The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
The parent entity
The component class
TRUE to incluide disabled entities and components. Default is FALSE.
SearchResult
const searchResult = entityManager.searchInChildren(parent, SpriteRenderer);
searchResult.forEach(({component, entity}) => {
// do something with the component and entity
})
const searchResult = entityManager.searchInChildren(parent, SpriteRenderer, true);
searchResult.forEach(({component, entity}) => {
// do something with the component and entity
})
Updates the data of a component instance
The entity
The component type
The callback to update the component
The EntityManager is responsible for managing the lifecycle and relationships of entities and components.
It provides methods for creating, reading, updating and deleting entities and their associated components.
Handles parent-child relationships between entities and enables/disables entities and components.
Acts as the central registry for all game objects and their behaviors.
Example