Component

Component

Base class/module for all components. Should not be used directly.

Constructor

new Component()

Members

debugLevel :string

Debug level for the component. Can be 'none', 'normal' or 'full'.
None will prevent the rendering of any debug meshes for the component.

enabled :boolean

If the component should be processed for containing entities.

entity :Entity

The entity the component is added to. The value is initially null and
is set and cleared by the default implementation of the attached and
detached, respectively.

Methods

(static) applyOnEntity(argument, entity) → {boolean}

Should be implemented in the same way in subclasses. Will be called by the World for each argument to world.createEntity(arg0, arg1, ...).
If this function returns true, it indicates that the passed argument was used and should not be passed to other components. See World.prototype.createEntity.

Parameters:
Name Type Description
argument
entity Entity

attached(entity)

Called when the component was added to an entity. The default implementation
sets the components entity property to the provided value.

Parameters:
Name Type Description
entity Entity

The entity being attached.

detached(entity)

Called when the component was removed from an entity. The default
implementation sets the component's entity property to null.

Parameters:
Name Type Description
entity Entity

The entity being detached.

ensureCanReplaceComponent(sourceEntity)

validate if the current component can be replaced by the same type component in sourceEntity.

This function is invoked by validateReplaceTo in Entity class.
This function MUST be overridden to enable replace for a specific component type.

Parameters:
Name Type Description
sourceEntity Entity
Throws:

Error if the component does not support the replace entity operation.