A node in the entity hierarchy, and a collection of components.

To iterate over the hierarchy, use the parent, firstChild, next and firstComponent fields. For example:

// Iterate over entity's children
var child = entity.firstChild;
while (child != null) {
    var next = child.next; // Store in case the child is removed in process()
    process(child);
    child = next;
}

Constructor

Properties

read only firstChild :Entity

This entity's first child.

read only firstComponent :Component

This entity's first component.

read only next :Entity

This entity's next sibling, for iteration.

read only parent :Entity

This entity's parent.

Methods

View source

_internal_getFromParents<A> (name :String, ?safeCast :Class<A>) :A

View source

add (component :Component) :Entity

Add a component to this entity. Any previous component of this type will be replaced.

Returns:

This instance, for chaining.

View source

addChild (entity :Entity, ?append :Bool = true) :Entity

Adds a child to this entity.

Parameters:

append

Whether to add the entity to the end or beginning of the child list.

Returns:

This instance, for chaining.

View source

dispose () :Void

Removes this entity from its parent, and disposes all its components and children.

View source

disposeChildren () :Void

Dispose all of this entity's children, without touching its own components or removing itself from its parent.

View source

get<A> (componentClass :Class<A>) :A

Gets a component of a given type from this entity.

View source

getComponent (name :String) :Component

Gets a component by name from this entity.

View source

getFromChildren<A> (componentClass :Class<A>) :A

Gets a component of a given type from this entity, or any of its children. Searches downwards in a depth-first search until the component is found, or returns null if not found.

View source

getFromParents<A> (componentClass :Class<A>) :A

Gets a component of a given type from this entity, or any of its parents. Searches upwards in the hierarchy until the component is found, or returns null if not found.

View source

has<A> (componentClass :Class<A>) :Bool

Checks if this entity has a component of the given type.

View source

remove (component :Component) :Bool

Remove a component from this entity.

Returns:

Whether the component was removed.