Constructor
new SoundEmitter(pos, sound, volume, speed, repeat, sprite, scale, temp, play, components)
Create a new SoundEmitter.
Parameters:
Name | Type | Description |
---|---|---|
pos | Vec2 | The position of the SoundEmitter, defaults to (0, 0) |
sound | string | | The identifier of the sound to emit, defaults to null |
volume | number | The volume of the sound, defaults to 1 |
speed | number | The playback speed of the sound, defaults to 1 |
repeat | boolean | Whether to repeat sound upon completion |
sprite | string | | Sprite for visual rendering (optional) |
scale | number | Scale of object (only relevant with sprites) |
temp | boolean | Whether emitter should be deleted once playback has finished, defaults to true |
play | boolean | Whether to play upon initialization, defaults to true |
components | Object.<string, ActorComponent> | Components to add |
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
sound
Get the identifier of the sound.
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
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
pause()
Pause the audio at the current time.
play(fromStart)
Play the audio from the current time, or the start.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fromStart | boolean | false | Whether to play audio from beginning |
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
stop()
Stop the audio and reset back to the beginning.
stopAnimations()
Stop all animations.
- Overrides
- Source
update(elapsed)
Update the position of the sound emitter relative to the space's camera.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update cycle |
- Overrides
Type Definitions
addChild
Add a child actor.
Type:
- Overrides
- Source