Actor#

Base class for objects in space.

Constructor#

new Actor(pos, rotation, scale, collision, sprite, persistent, events, components, id)#

Create a new actor.
Parameters:
NameTypeDescription
posVec2Initial position in space
rotationnumberRotation around center
scalenumberUniform scaling for rendering
collision"auto" | nullCollision initializer
spriteSprite | string | nullSprite or sprite identifier for rendering
persistentbooleanWhether to always update regardless of loaded chunks
eventsObject.<string, (function()|Array.<function()>)>Events to register
componentsObject.<string, ActorComponent>Components to add
idstringGlobal (in space) identifier of actor

Members#

collisionBounds#

Get the total bounding box of all collision components.

components#

Get the component manager.

drawableBounds#

Get the total bounding box of all drawable components.

globalID#

Get the global identifier.

globalID#

Set the global (space) identifier.

globalPos#

Get the global position.

globalPos#

Set the global (absolute) position.

initialized#

Check if the actor has been initialized.

pos#

Get the local position.

pos#

Set the local (relative) position.

Methods#

addAnimation(animation) → {ActorAnimation}#

Add an animation.
Parameters:
NameTypeDescription
animationActorAnimationAnimation to add
Returns:
Animation that was added
Type: 
ActorAnimation

checkCollision(other, pos) → {Object}#

Check collision with another actor.
Parameters:
NameTypeDescription
otherCollisionComponentOther component to check with
posVec2The position to attempt to move to
Returns:
Collision result
Type: 
Object

clearChildren()#

Remove and delete all child actors.

clearOverlappingChunks()#

Clear and remove actor from all overlapping chunks.

delete()#

Mark the actor for deletion.

doEvent(event, …args)#

Run all functions attached to a specified event.
Parameters:
NameTypeAttributesDescription
eventActorEvent | stringEvent to trigger
argsany<repeatable>
Arguments to pass into functions

draw(ctx)#

Draw the actor
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DThe canvas context to draw on

drawDebug(ctx, showID, showDot)#

Draw debug information for the actor (if enabled).
Parameters:
NameTypeDefaultDescription
ctxCanvasRenderingContext2DCanvas context to draw on
showIDbooleantrueWhether to show chunk actor ID
showDotbooleantrueWhether to show the dot in the center

findOverlappingChunks()#

Find, save, and register in all chunks that collision components are overlapping with.

forEachChild(func)#

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

getTransformMatrix(trans, rot, scale)#

Get the global transformation matrix.
Parameters:
NameTypeDefaultDescription
transbooleantrueWhether to include translation
rotbooleantrueWhether to include rotation
scalebooleantrueWhether to include scaling
Returns:
Global transformation matrix

hasAnimations() → {boolean}#

Check if there are any active animations.
Returns:
Whether any animations are active
Type: 
boolean

hasParent() → {boolean}#

Check if the actor has a parent actor.
Returns:
Whether actor has a parent
Type: 
boolean

init()#

Executed when an actor is added to a space.

on(event, func)#

Add an event function.
Parameters:
NameTypeDescription
eventActorEvent | stringEvent to add function to
funcfunctionFunction to run when called

removeChild(actor)#

Remove a child actor. This will delete the actor.
Parameters:
NameTypeDescription
actorActorChild to remove

resetShadow(ctx)#

Reset/remove the shadow for drawing.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

setParent(actor)#

Set the parent actor (do not call this manually).
Parameters:
NameTypeDescription
actorActorNew parent actor.

setShadow(ctx)#

Set up the shadow for drawing.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

stopAnimations()#

Stop all animations.

update(elapsed)#

Update the actor
Parameters:
NameTypeDescription
elapsednumberTime since last update

Type Definitions#

addChild#

Add a child actor.
Type: