Camera

new Camera(pos, toFollow)

Create a new camera.
Parameters:
NameTypeDefaultDescription
posVec2Initial position
toFollowActor | nullnullActor to follow/track (optional)

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

calcZoom() → {number}

Get the actual value of the zoom.
Returns:
Actual zoom value
Type: 
number

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

doFollow(elapsed)

Do the translation of the camera in following the actor, if one is set.
Parameters:
NameTypeDescription
elapsednumberTime elapsed since last update

doShake(strength, length)

Initialize a new camera shake effect.
Parameters:
NameTypeDefaultDescription
strengthnumberIntensity of the effect
lengthnumber1Duration of the effect

draw(ctx)

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

drawDebug(ctx, showID, showDot)

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

drawFilter(ctx)

Draw the current filter over the game, if there is one.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

fadeIn(color, duration, after)

Add a fade in effect.
Parameters:
NameTypeDescription
colorColorColor to fade in to (black by default)
durationnumberLength of fade effect
afterfunctionFunction to run when complete

fadeOut(color, duration, after)

Add a fade out effect.
Parameters:
NameTypeDescription
colorColorColor to fade out to (black by default)
durationnumberLength of fade effect
afterfunctionFunction to run when complete

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

getOffset() → {Vec2}

Get the positional offset of the relative to the game canvas and camera. Used for drawing the world and querying mouse position.
Returns:
Positional offset of game canvas and camera
Type: 
Vec2

getOffsetWithZoom() → {Vec2}

Get the positional offset of the relative to the game canvas and camera, while taking magnification into account. Similar to getOffset().
Returns:
Positional offset of game canvas and camera, with the zoom taken into account
Type: 
Vec2

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 camera.
Parameters:
NameTypeDescription
elapsednumberTime since last update in seconds
Overrides

Type Definitions

addChild

Add a child actor.
Type: