Entity

new Entity()

An entity is a game object. All the Objects in the game are entities. Entities can have components attached to them. Entities can have children entities, which can be used to create a hierarchy of entities.

Example
// Create a new entity
let entity = new Entity("Box");

Members

children :Array.<Entity>

Children of this entity.

Type:

(protected, readonly) components :Array.<Component>

Component attached to this entity.

Type:

(protected) name :string

Name of the entity. Names are not processed by the engine. They are used for debugging purposes.

Type:
  • string

parent :Entity

Parent Entity of this entity. If this entity is the root entity, this will be null.

Type:

Methods

AddChild(child)

Adds a child entity to this entity. This checks if the child is already added to the entity. If it is, it will not be added again.

Parameters:
NameTypeDescription
childEntity

The child entity to be added.

Example
// Create a new entity
let entity = new Entity("Box");

// Create a new child entity
let child = new Entity("Child");

// Add the child entity to the parent entity
entity.AddChild(child);

AddChildren(…children)

Adds multiple child entities to this entity.

Parameters:
NameTypeAttributesDescription
childrenArray.<Entity><repeatable>

The child entities to be added.

Example
// Create a new entity
let entity = new Entity("Box");
let childEntity1 = new Entity("Child1");
let childEntity2 = new Entity("Child2");
let childEntity3 = new Entity("Child3");

// Add the child entities to the parent entity
entity.AddChildren(childEntity1, childEntity2, childEntity3);

AddComponent(component)

Adds a component to the entity. This checks if the component is already attached to the entity. If it is, it will not be added again.

Parameters:
NameTypeDescription
componentComponent

The component to be added.

Example
// Add a transform component to the entity
entity.AddComponent(new Transform());

GetChildren() → {Array.<Entity>}

Get all children of this entity.

Returns:

The children of this entity.

Type: 
Array.<Entity>

GetChildWithComponent(type) → {Entity}

Gets the child entity with the specified component type.

Parameters:
NameTypeDescription
typeComponent

The type of the component to be returned.

Returns:

The child entity with the specified component type.

Type: 
Entity
Example
// Get the first child entity with a transform component 
let child = entity.GetChildWithComponent(Transform);

GetComponent(type) → {Component}

Returns the component of the given type attached to this entity.

Parameters:
NameTypeDescription
typeComponent

The type of the component to be returned.

Returns:

The component of the given type attached to this entity.

Type: 
Component
Example
// Get the transform component of the entity
let transform = entity.GetComponent(Transform);

GetComponentsInChildren(type) → {Array.<Component>}

Get a component of the given type attached to the children. Returns all the components of the given type attached to all the children.

Parameters:
NameTypeDescription
typeComponent

The type of the component to be returned.

Returns:

The components of the given type attached to the children.

Type: 
Array.<Component>
Example
// Get the transform components of all the children of the entity
let transforms = entity.GetComponentsInChildren(Transform);

GetParent() → {Entity}

Returns the parent of this entity.

Returns:

The parent of this entity.

Type: 
Entity

GetTree() → {Object}

Generate a tree with the children of this entity. Components are not included in the tree.

Returns:

The tree with the children of this entity.

Type: 
Object
Example
// Generate a tree with the children of the entity
let tree = entity.GetTree();

HasComponent(type) → {boolean}

Returns true if the entity has a component of the given type.

Parameters:
NameTypeDescription
typeComponent

The type of the component to be checked.

Returns:

True if the entity has a component of the given type.

Type: 
boolean
Example
// Check if the entity has a transform component
let hasTransform = entity.HasComponent(Transform);

RemoveComponent(type)

Removes the component of the given type from the entity.

Parameters:
NameTypeDescription
typeComponent

The type of the component to be removed.

Example
// Remove the transform component from the entity
entity.RemoveComponent(Transform);