Particle

new Particle(pos, lifespan, sprite, rotation, spin, scale, opacity, velocity)

Create a new particle.
Parameters:
NameTypeDescription
posVec2Initial position
lifespannumberTotal lifespan
spritestring | SpriteSprite or identifier of sprite to use
rotation"random" | numberInitial rotation
spinNumberSpin over time
scaleVec2GradientScale over time
opacityNumberGradientOpacity over time
velocityVec2GradientVelocity of time

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

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

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: