Open Source Cross-Platform Game Programming

Audio

Provides audio functionality for games using the Game library. All sound resources must be OGG files.

enum SoundPlayState[link]

Current state of a sound

NameDescription
PLAYING

Sound is currently playing

PAUSED

Sound is paused

STOPPED

Sound has stopped

class Music[link]

Encapsulates a sound file for the purpose of playing music. Supports looping and fading transitions, but only supports one sound playback at a time.

function fadeIn(loop, inTransition)[link]

Stops the currently playing music (if any) and fades in this music.

Arguments

NameTypeOptionalDescription
loop boolean Optional

True if this music should loop indefinitely.

inTransition float Optional

Number of seconds to fade this music in

function fadeOut(outTransition)[link]

Fades out this music if it is currently playing. See also Music.fadeOutCurrent()

Arguments

NameTypeOptionalDescription
outTransition float Optional

Number of seconds to fade out

function fadeOutAndIn(loop, outTransition, inTransition)[link]

Fades out the currently playing music (if any) and fades in this music.

Arguments

NameTypeOptionalDescription
loop boolean Optional

True if this music should loop indefinitely.

outTransition float Optional

Number of seconds to fade the current music out

inTransition float Optional

Number of seconds to fade this music in

function fadeOutAndPlay(loop, outTransition)[link]

Fades out the currently playing music (if any) and starts playing this music.

Arguments

NameTypeOptionalDescription
loop boolean Optional

True if this music should loop indefinitely.

outTransition float Optional

Number of seconds to fade the current music out

function fadeOutCurrent(outTransition)[link]

Fades out the current music, if any.

Arguments

NameTypeOptionalDescription
outTransition float Optional

Number of seconds to fade the current music out

function getCurrent()[link]

null

Return Value

TypeDescription
Audio.Music

The currently playing music.

function loadFromResource(path)[link]

null

Arguments

NameTypeDescription
path string

path to a bundled OGG resource

Return Value

TypeDescription
Audio.Music

A new Audio.Music instance

function play(loop)[link]

Stops the currently playing music (if any) and starts playing this music.

Arguments

NameTypeOptionalDescription
loop boolean Optional

True if this music should loop indefinitely.

function stop()[link]

Stops the current music, if any.

class MusicNotFoundException[link]

An exception thrown when the music being attempted to load is not found.

class Sound[link]

Represents a sound that is currently active. Sound instances are created from the SoundResource.play() method.

function getPan()[link]

Gets the pan value for this sound. Pan is a value from -1.0 to 1.0 that represents which speaker this sound should come out of. -1.0 is the left speaker, 1.0 is the right speaker, and 0.0 is centered. Pan is not supported on all platforms, but this value is still persisted and returned after setting it with setPan or play.

function getResource()[link]

Gets a reference to the original SoundResource object of this Sound.

Return Value

TypeDescription
Audio.SoundResource

Reference to the original SoundResource

function getState()[link]

Gets the current state of the sound playback.

Return Value

TypeDescription
Audio.SoundPlayState

Current state of the sound playback.

function getVolume()[link]

Gets the the current volume of the playing sound.

Return Value

TypeDescription
float

The current volume of the sound as a ratio from 0.0 to 1.0

function resume()[link]

Resumes a sound that has been paused.

function setPan(value)[link]

Sets the pan value for this sound. Pan is not always supported by the platform, in which case this function will do nothing.

Arguments

NameTypeDescription
value float

The pan value as a ratio from -1.0 to 1.0. 0.0 represents a centered sound, while -1 will play exclusively from the left speak and 1 will play from the right speaker.

function setVolume(ratio)[link]

Sets the volume of the currently playing sound. See also Audio.SoundResource.setDefaultVolume.

Arguments

NameTypeDescription
ratio float

A volume ratio between 0.0 and 1.0

function stop()[link]

Stops a sound that is playing. It cannot be resumed. If you want to resume playback, use pause() instead.

class SoundResource[link]

Represents a file that can be played as a sound effect.

function getDefaultVolume()[link]

Gets the default volume ratio for Audio.Sound objects that are played from this resource.

Return Value

TypeDescription
float

Volume ratio from 0.0 to 1.0.

function loadFromFile(path)[link]

Creates a new Audio.SoundResource instance for the given file.

Arguments

NameTypeDescription
path string

Absolute or relative path to a sound file on the local disk.

function loadFromResource(path)[link]

Creates a new Audio.SoundResource instance for the given bundled resource.

Arguments

NameTypeDescription
path string

Path to a bundled resource

function play(pan)[link]

Plays this SoundResource. Returns a handle to a Audio.Sound instance which represents the current playback session. This handle can be used to pause the sound or change attributes of the playback such as volume and pan. Ignoring this handle is okay as well, if you want the sound to play normally without changing attributes or pausing it. You can optionally also pass in a default pan value to control which speakers this sound plays from (rather than adjusting it while it's playing).

Arguments

NameTypeOptionalDescription
pan float Optional

Default pan value for playing this sound.

Return Value

TypeDescription
Audio.Sound

A reference to the Sound scoped to this playback instance that can be used to pause, change volume, change pan, etc.

function setDefaultVolume(ratio)[link]

Sets the default volume ratio for Audio.Sound objects that are played from this resource.

Arguments

NameTypeDescription
ratio float

A volume ratio from 0.0 to 1.0.