MovingActor

new MovingActor(pos, Initial, Initial, sprite, collision, controller, speed)

Create a new moving actor.
Parameters:
NameTypeDescription
posVec2Initial position of actor
Initialnumberrotation of actor
Initialnumber | Vec2scale of actor
spritestring | Sprite | nullSprite for visual rendering
collision"auto" | nullCollision initializer (optional)
controllerstring | Controller | nullController for user movement (optional)
speednumberSpeed of movement (300 by default)

Extends

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.

globalPos

Get the global position.

initialized

Check if the actor has been initialized.

pos

Get the local position.
Overrides

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.
Overrides

doEvent(event, …args)

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

doMove(move, elapsed)

Perform the movement controlled by a controller.
Parameters:
NameTypeDescription
moveVec2Movement vector
elapsednumberTime since last update

doMoveIter(elapsed)

Perform multiple movements in a single frame. Helps with accuracy.
Parameters:
NameTypeDescription
elapsednumberTime since last update cycle in seconds

draw(ctx)

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

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.
Overrides

on(event, func)

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

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

setController(id)

Set the controller of the moving actor.
Parameters:
NameTypeDescription
idstringID of the controller type to use

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
Overrides

Type Definitions

addChild

Add a child actor.
Type: