Skip to content

Audio

The Audio class enables loading and playing sound effects (SE) or background music (BGM) tracks.


Synopsis

Constructor

Static Methods

Instance Methods


Constructor

Audio(path, [streaming])

Loads an audio resource from the specified path as a sound effect.

Parameters:

Parameter Type Required Description
path string Yes The path to the audio asset.
streaming bool No If true, the file is streamed from disk rather than fully loaded into memory. Default is false.

Static Methods

Audio.bgm_play(path[, options])

Loads and plays an audio file as background music. BGM tracks are automatically streamed.

Parameters:

Parameter Type Required Description
path string Yes Path to the music file.
options table No Advanced playback modifiers (see Play Options).

Audio.bgm_playing()

Checks whether background music is currently active.

  • Returns: bool: true if background music is playing, false otherwise.

Audio.bgm_stop()

Stops the currently playing background music.

Audio.bgm_pause()

Pauses the currently playing background music.

Audio.bgm_resume()

Resumes the currently paused background music.


Instance Methods

audio.play([options])

Plays a previously loaded sound effect.

Play Options Table

Field Type Default Description
loops int 0 Additional loops to play (-1 for infinite).
pan float 0.0 Stereo panning (-1.0 Left, 0.0 Center, 1.0 Right).
pitch float 1.0 Playback pitch modifier.
position int 0 Starting position in milliseconds.
volume float 1.0 Playback volume multiplier.

Examples

// Load a sound effect
local clickSound = Audio("assets/audio/click.wav")

// Play sound effect
clickSound.play()

// Play sound effect with lowered volume
clickSound.play({ volume = 0.75})

// Start to play a background music track
Audio.bgm_play("assets/audio/music.ogg")