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.
Name | Type | Description |
---|---|---|
id | number | Id of the scene. This is used to load the scene. |
- Source
Extends
Members
children :Array.<Entity>
Children of this entity.
- Array.
<Entity>
- Inherited From
- Source
(protected, readonly) components :Array.<Component>
Component attached to this entity.
- Array.
<Component>
- Inherited From
- Source
(protected) name :string
Name of the entity. Names are not processed by the engine. They are used for debugging purposes.
- string
- Inherited From
- Source
OnSceneLoad
Called when The scene is loaded
- Source
OnSceneLoadAdditive
Called when the scene is loaded in additive mode
- Source
OnSceneUnload
Called when the scene is unloaded
- Source
OnSceneUnloadAdditive
Called when the scene is unloaded in additive mode
- Source
parent :Entity
Parent Entity of this entity. If this entity is the root entity, this will be null.
- Inherited From
- Source
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.
Name | Type | Description |
---|---|---|
child | Entity | The child entity to be added. |
- Inherited From
- Source
// 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.
Name | Type | Attributes | Description |
---|---|---|---|
children | Array. | <repeatable> | The child entities to be added. |
- Inherited From
- Source
// 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.
Name | Type | Description |
---|---|---|
component | Component | The component to be added. |
- Inherited From
- Source
// Add a transform component to the entity
entity.AddComponent(new Transform());
GetChildren() → {Array.<Entity>}
Get all children of this entity.
- Inherited From
- Source
The children of this entity.
- Type:
- Array.
<Entity>
GetChildWithComponent(type) → {Entity}
Gets the child entity with the specified component type.
Name | Type | Description |
---|---|---|
type | Component | The type of the component to be returned. |
- Inherited From
- Source
The child entity with the specified component type.
- Type:
- Entity
// 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.
Name | Type | Description |
---|---|---|
type | Component | The type of the component to be returned. |
- Inherited From
- Source
The component of the given type attached to this entity.
- Type:
- Component
// 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.
Name | Type | Description |
---|---|---|
type | Component | The type of the component to be returned. |
- Inherited From
- Source
The components of the given type attached to the children.
- Type:
- Array.
<Component>
// 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
- Source
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
- Source
The tree with the children of this entity.
- Type:
- Object
// 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.
Name | Type | Description |
---|---|---|
type | Component | The type of the component to be checked. |
- Inherited From
- Source
True if the entity has a component of the given type.
- Type:
- boolean
// 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.
Name | Type | Description |
---|---|---|
type | Component | The type of the component to be removed. |
- Inherited From
- Source
// Remove the transform component from the entity
entity.RemoveComponent(Transform);