Class: Component

Component

A Component is an object that can be added to an Entity to add behavior to it in a modular fashion. This can be useful to create small pieces of functionality that can be reused often and without extra boilerplate code.

If it implements an onUpdate(dt) function, the update method will be called every frame.

A single Component instance is unique to an Entity and cannot be shared!

Custom Component subclasses need to be registered for use with:


Component.register(name, classRef);

The name parameter is used to access component instances using the Entity#components.name[] Array. By default, the name is the same as the class name but starting with a lowercase letter.

A component class can have a static member dependencies, which is an Array listing the components it requires to be added to an Entity first.


<abstract> new Component()

Properties:
Name Type Description
entity

The entity the component is assigned to.

Author:
  • derschmale <http://www.derschmale.com>
See:

Members


acceptVisitor

If provided, this method will be called by the scene partition traverser, allowing collection by the renderer.


bounds

If a Component has a scene presence, it can have bounds


enabled

Defines whether or not this component should be enabled.


onUpdate

If provided, this method will be called every frame, allowing updating the entity.

Methods


bindListener()

Listens to the entity's messenger for a given message type.


broadcast()

Broadcasts a message dispatched by the owning Entity's onMessage Signal.


clone()

Creates a duplicate of this Component.


hasListeners()

Tests whether the given signal is being listened to.


invalidateBounds()

Marks the bounds as invalid, causing them to be recalculated when next queried.


onAdded()

Called when this component is added to an Entity.


onRemoved()

Called when this component is removed from an Entity.


unbindListener()

Listens to the entity's messenger for a given message type.