Audio
Global audio state (listener) and creation/control of Source objects. Sources are created from mounted audio paths (WAV, MP3, OGG, FLAC depending on build). All Audio methods are static.
Creating sources
Section titled “Creating sources”Audio.newSource(path)
Section titled “Audio.newSource(path)”Returns: Source or null — A new source, or null if the file could not be loaded.
Parameters:
path(String) — Path to the audio file relative to the mounted project (e.g."sounds/click.wav").
_clickSource = Audio.newSource("sounds/click.wav")if (_clickSource != null) { Audio.play(_clickSource)}Global playback
Section titled “Global playback”Audio.play(source) / Audio.stop(source) / Audio.stop()
Section titled “Audio.play(source) / Audio.stop(source) / Audio.stop()”Parameters:
source(Source, optional) — Source to play or stop.Audio.stop()with no arguments stops all playback.
Play a source, or stop a specific source or all playback.
Audio.play(_musicSource)Audio.stop(_musicSource)Audio.stop() // stop allAudio.isPlaying(source)
Section titled “Audio.isPlaying(source)”Returns: Bool — true if the given source is currently playing.
Parameters:
source(Source) — Source to check.
Audio.pause()
Section titled “Audio.pause()”Pause global playback.
Listener (volume & 3D)
Section titled “Listener (volume & 3D)”Audio.getVolume() / Audio.setVolume(vol)
Section titled “Audio.getVolume() / Audio.setVolume(vol)”Returns: (getter) Num — Global volume (0–1 or engine-defined range).
Parameters:
vol(Num) — Volume (0–1 typical).
Audio.getPosition() / Audio.setPosition(x, y, z)
Section titled “Audio.getPosition() / Audio.setPosition(x, y, z)”Returns: (getter) List of three numbers [x, y, z] — Listener position in world space.
Parameters:
x,y,z(Num) — Listener position.
Audio.getOrientation() / Audio.setOrientation(atX, atY, atZ, upX, upY, upZ)
Section titled “Audio.getOrientation() / Audio.setOrientation(atX, atY, atZ, upX, upY, upZ)”Returns: (getter) Orientation (at and up vectors).
Parameters:
atX,atY,atZ(Num) — “At” (forward) direction.upX,upY,upZ(Num) — “Up” direction.
Audio.getVelocity() / Audio.setVelocity(x, y, z)
Section titled “Audio.getVelocity() / Audio.setVelocity(x, y, z)”Returns: (getter) List [x, y, z] — Listener velocity (for Doppler).
Parameters:
x,y,z(Num) — Velocity.
Audio.getDistanceModel() / Audio.setDistanceModel(model)
Section titled “Audio.getDistanceModel() / Audio.setDistanceModel(model)”Returns: (getter) Current distance model.
Parameters:
model— Distance attenuation model (implementation-dependent).
Audio.getDopplerScale() / Audio.setDopplerScale(scale)
Section titled “Audio.getDopplerScale() / Audio.setDopplerScale(scale)”Returns: (getter) Num — Doppler scale.
Parameters:
scale(Num) — Doppler effect scale.
Audio.getActiveSourceCount()
Section titled “Audio.getActiveSourceCount()”Returns: Num — Number of sources currently playing.
Source
Section titled “Source”A single sound source. Create with Audio.newSource or Resource.loadSound.
Playback
Section titled “Playback”| Method | Returns | Parameters | Description |
|---|---|---|---|
play() | — | — | Start playback |
stop() | — | — | Stop playback |
pause() | — | — | Pause playback |
getVolume() | Num | — | Current volume |
setVolume(vol) | — | vol (Num) | Set volume |
getPitch() | Num | — | Current pitch |
setPitch(p) | — | p (Num) | Set pitch |
isLooping() | Bool | — | Whether looping |
setLooping(loop) | — | loop (Bool) | Set looping |
getDuration() | Num | — | Length in seconds |
tell() | Num | — | Current position in seconds |
seek(offsetSeconds) | — | offsetSeconds (Num) | Seek to position |
clone() | Source | — | New source with same buffer |
3D sound
Section titled “3D sound”| Method | Returns / Parameters | Description |
|---|---|---|
getPosition() | [x, y, z] | Source position |
setPosition(x, y, z) | x, y, z (Num) | Set position |
getVelocity() / setVelocity(x, y, z) | — | Velocity for Doppler |
getDirection() / setDirection(x, y, z) | — | Direction vector |
getCone() / setCone(innerAngle, outerAngle, outerGain) | — | Directional cone (angles in radians) |
getAttenuationDistances() / setAttenuationDistances(refDist, maxDist) | — | Distance attenuation |
getRolloff() / setRolloff(rolloff) | — | Rolloff factor |
isRelative() / setRelative(rel) | Bool | Relative to listener |
var src = Audio.newSource("sounds/music.wav")src.setLooping(true)src.setVolume(0.8)src.setPosition(5, 0, 0)Audio.play(src)