new MovingActor(pos, Initial, Initial, sprite, collision, controller, speed)
Create a new moving actor.
Parameters:
Name | Type | Description |
---|---|---|
pos | Vec2 | Initial position of actor |
Initial | number | rotation of actor |
Initial | number | | scale of actor |
sprite | string | | Sprite for visual rendering |
collision | "auto" | | Collision initializer (optional) |
controller | string | | Controller for user movement (optional) |
speed | number | Speed of movement (300 by default) |
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
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
doMove(move, elapsed)
Perform the movement controlled by a controller.
Parameters:
Name | Type | Description |
---|---|---|
move | Vec2 | Movement vector |
elapsed | number | Time since last update |
doMoveIter(elapsed)
Perform multiple movements in a single frame. Helps with accuracy.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update cycle in seconds |
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 actor (if enabled).
Parameters:
Name | Type | Default | Description |
---|---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on | |
showID | boolean | true | Whether to show chunk actor ID |
showDot | boolean | true | Whether to show the dot in the center |
- Overrides
- Source
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
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
setController(id)
Set the controller of the moving actor.
Parameters:
Name | Type | Description |
---|---|---|
id | string | ID of the controller type to use |
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 actor
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update |
- Overrides
- Source
Type Definitions
addChild
Add a child actor.
Type:
- Overrides
- Source