new Camera(pos, toFollow)
Create a new camera.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
pos | Vec2 | Initial position | |
toFollow | Actor | | null | Actor to follow/track (optional) |
Extends
Members
collisionBounds
Get the total bounding box of all collision components.
- Overrides
- Source
components
Get the component manager.
- Overrides
- Source
drawableBounds
Get the total bounding box of all drawable components.
- Overrides
- Source
globalID
Get the global identifier.
- Overrides
- Source
globalPos
Get the global position.
- Overrides
- Source
initialized
Check if the actor has been initialized.
- Overrides
- Source
pos
Get the local position.
- Overrides
- Source
Methods
addAnimation(animation) → {ActorAnimation}
Add an animation.
Parameters:
Name | Type | Description |
---|---|---|
animation | ActorAnimation | Animation to add |
- Overrides
- Source
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:
Name | Type | Description |
---|---|---|
other | CollisionComponent | Other component to check with |
pos | Vec2 | The position to attempt to move to |
- Overrides
- Source
Returns:
Collision result
- Type:
- Object
clearChildren()
Remove and delete all child actors.
- Overrides
- Source
clearOverlappingChunks()
Clear and remove actor from all overlapping chunks.
- Overrides
- Source
delete()
Mark the actor for deletion.
- Overrides
- Source
doEvent(event, …args)
Run all functions attached to a specified event.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event | ActorEvent | | Event to trigger | |
args | any | <repeatable> | Arguments to pass into functions |
- Overrides
- Source
doFollow(elapsed)
Do the translation of the camera in following the actor, if one is set.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time elapsed since last update |
doShake(strength, length)
Initialize a new camera shake effect.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
strength | number | Intensity of the effect | |
length | number | 1 | Duration of the effect |
draw(ctx)
Draw the actor
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | The canvas context to draw on |
- Overrides
- Source
drawDebug(ctx, showID, showDot)
Draw debug information for the camera (if enabled).
Parameters:
Name | Type | Default | Description |
---|---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on | |
showID | boolean | false | Whether to show chunk actor ID |
showDot | boolean | true | Whether to show the dot in the center |
- Overrides
drawFilter(ctx)
Draw the current filter over the game, if there is one.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
fadeIn(color, duration, after)
Add a fade in effect.
Parameters:
Name | Type | Description |
---|---|---|
color | Color | Color to fade in to (black by default) |
duration | number | Length of fade effect |
after | function | Function to run when complete |
fadeOut(color, duration, after)
Add a fade out effect.
Parameters:
Name | Type | Description |
---|---|---|
color | Color | Color to fade out to (black by default) |
duration | number | Length of fade effect |
after | function | Function to run when complete |
findOverlappingChunks()
Find, save, and register in all chunks that collision components are overlapping with.
- Overrides
- Source
forEachChild(func)
Run a function for each child actor.
Parameters:
Name | Type | Description |
---|---|---|
func | function | Function to run for each child |
- Overrides
- Source
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:
Name | Type | Default | Description |
---|---|---|---|
trans | boolean | true | Whether to include translation |
rot | boolean | true | Whether to include rotation |
scale | boolean | true | Whether to include scaling |
- Overrides
- Source
Returns:
Global transformation matrix
hasAnimations() → {boolean}
Check if there are any active animations.
- Overrides
- Source
Returns:
Whether any animations are active
- Type:
- boolean
hasParent() → {boolean}
Check if the actor has a parent actor.
- Overrides
- Source
Returns:
Whether actor has a parent
- Type:
- boolean
init()
Executed when an actor is added to a space.
- Overrides
- Source
on(event, func)
Add an event function.
Parameters:
Name | Type | Description |
---|---|---|
event | ActorEvent | | Event to add function to |
func | function | Function to run when called |
- Overrides
- Source
removeChild(actor)
Remove a child actor. This will delete the actor.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Child to remove |
- Overrides
- Source
resetShadow(ctx)
Reset/remove the shadow for drawing.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
- Overrides
- Source
setParent(actor)
Set the parent actor (do not call this manually).
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | New parent actor. |
- Overrides
- Source
setShadow(ctx)
Set up the shadow for drawing.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
- Overrides
- Source
stopAnimations()
Stop all animations.
- Overrides
- Source
update(elapsed)
Update the camera.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update in seconds |
- Overrides
Type Definitions
addChild
Add a child actor.
Type:
- Overrides
- Source