Scene

new Scene()

Scene is a container for entities. It is used to organize the game objects in the game. SceneManager is used to load and unload scenes. A scene can be used to only load specific entities. If any entity is not part of a scene, it will be loaded by default.

Properties
NameTypeDescription
idnumber

Id of the scene. This is used to load the scene.

Extends

Members

children :Array.<Entity>

Children of this entity.

Type:
Inherited From

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

Component attached to this entity.

Type:
Inherited From

(protected) name :string

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

Type:
  • string
Inherited From

OnSceneLoad

Called when The scene is loaded

OnSceneLoadAdditive

Called when the scene is loaded in additive mode

OnSceneUnload

Called when the scene is unloaded

OnSceneUnloadAdditive

Called when the scene is unloaded in additive mode

parent :Entity

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

Type:
Inherited From

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.

Inherited From
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.

Inherited From
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.

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

GetChildren() → {Array.<Entity>}

Get all children of this entity.

Inherited From
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.

Inherited From
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.

Inherited From
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.

Inherited From
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.

Inherited From
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);