ComponentManager

Manager for components of an actor.

Constructor

new ComponentManager(actor)

Create a new component manager.
Parameters:
NameTypeDescription
actorActorActor to be a part of

Members

collisionCount

Get the amount of CollisionComponents

count

Get the total number of components.

drawableCount

Get the amount of DrawableComponents.

physicsCount

Get the amount of PhysicsComponents

Methods

destructor()

Call the destructor for all attached components.

drawAll(ctx)

Draw all drawable components.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context for drawing

drawDebugAll(ctx)

Draw debug info for all drawable components.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context for drawing

forAll(func)

Run a function for each component.
Parameters:
NameTypeDescription
funcfunctionFunction to run for each component

get(id) → {ActorComponent}

Get a specific component.
Parameters:
NameTypeDescription
idstringIdentifier of component
Returns:
Specified component
Type: 
ActorComponent

getAll() → {IterableIterator.<ActorComponent>}

Get an iterable iterator of all components.
Returns:
All components
Type: 
IterableIterator.<ActorComponent>

getCollisions() → {IterableIterator.<CollisionComponent>}

Get an iterable iterator of all CollisionComponents.
Returns:
All collision components
Type: 
IterableIterator.<CollisionComponent>

getDrawables() → {IterableIterator.<DrawableComponent>}

Get an iterable iterator of all DrawableComponents.
Returns:
All drawable components
Type: 
IterableIterator.<DrawableComponent>

getPhysics() → {IterableIterator.<PhysicsComponent>}

Get an iterable iterator of all PhysicsComponents.
Returns:
All physics components
Type: 
IterableIterator.<PhysicsComponent>

has(id) → {boolean}

Check if the actor has a component with a specified identifier.
Parameters:
NameTypeDescription
idstringIdentifier to check for
Returns:
Whether actor has component with specified identifier
Type: 
boolean

remove(id)

Remove a component from the actor.
Parameters:
NameTypeDescription
idstringIdentifier of component to remove

updateAll(elapsed)

Update all components.
Parameters:
NameTypeDescription
elapsednumberTime since last update frame in seconds