ComponentContainer

Interface class for objects that have components. A SceneObject has components, and a Component can have a hierarchy of other components.

Mixins

ComponentContainer

Methods

addComponent(component, options)

Add a component to the object.

Parameters
component Component | String

The component to add

options Object

getComponent(classType, index) → nullable Component

Return the first (or n'th) component of the given type.

Parameters
classType String | Class

Can be a String or Class

index int

Optional index of the component to get.

Returns
Component

getComponents(classType)

Return all components of the object with the given type.

Parameters
classType Array

getOrAddComponent(componentType, options) → nullable Component

If the object has a component of the given type, return that. Otherwise, a new component of the given type is created and added to the object.

Parameters
componentType String | Class

The type of the component

options Object

Options if the component is created.

Returns
Component

The existing or new component, null if component wasn't able to be created.

hasComponent(classType) → bool

Does the object have a component of the given type?

Parameters
classType String | Class
Returns
bool

True if the object has a component.

removeAllComponents()

Remove all components from the object.

removeComponent(componentType) → bool

Remove a component from the object.

Parameters
componentType String | Component

The type of the component to remove.

Returns
bool

True if a component was removed, false if not.