Skip to content

API - Audio

Allows sound effects to play inside a space.

When extending BasePlugin, these functions can be accessed via this.audio.*

When extending BaseComponent, these functions can be accessed via this.plugin.audio.*

Functions

preload(url)

Prepares to play a sound file.

Can be used to prevent a delay when the sound is played for the first time, by calling this method in the onLoad() method inside the plugin or component.

Field Type Description Example
url string URL of the sound file. Can be a local path or absolute URL this.paths.absolute('./sound.wav')
or
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1506195/keyboard-32-12.mp3'

play(url, settings={})

Plays a sound file.

Field Type Description Example
url string URL of the sound file. Can be a local path or absolute URL this.paths.absolute('./sound.wav')
or
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1506195/keyboard-32-12.mp3'
settings object Additional settings controlling the sound file. See below for all available properties { volume: 0.68 }

Properties available for the settings parameter

Property Type Description Example
volume number Adjusts the volume. Must be a value between 0 and 1 0.68
x number World x co-ordinate at which to play the sound 3
y number World y co-ordinate at which to play the sound 12.6
height number World height co-ordinate at which to play the sound 0.15
radius number Radius around which to play the audio. Controls how far the sound can be heard 4.5
Back to top