API Docs for: 1.13.1
Show:

game.Audio Class

Extends game.Class
Module: audio

Methods

isMusicPlaying

() Boolean

Check if music is playing.

Returns:

Boolean:

isSoundPlaying

(
  • id
)
Boolean

Check if sound is playing.

Parameters:

  • id Number

Returns:

Boolean:

muteMusic

()

Mute current music.

muteSound

(
  • [id]
)
Boolean

Mute specific sound or all sounds.

Parameters:

  • [id] Number optional

    Id of sound

Returns:

Boolean:

pauseMusic

() Boolean

Pause current music.

Returns:

Boolean:

pauseSound

(
  • [id]
)
Boolean

Pause specific or all sounds.

Parameters:

  • [id] Number optional

    Id of sound

Returns:

Boolean:

Return false, if sound is not playing

playMusic

(
  • name
  • [loop]
)
Boolean

Play music.

Parameters:

  • name Number

    Name of music

  • [loop] Boolean optional

    Music looping

Returns:

Boolean:

playSound

(
  • name
  • [loop]
  • [callback]
  • [rate]
)
Number

Play sound.

Parameters:

  • name String

    Name of sound

  • [loop] Boolean optional

    Sound looping

  • [callback] Function optional

    Callback when sound is finished

  • [rate] Number optional

    Playback rate (Web Audio)

Returns:

Number:

id

resumeMusic

() Boolean

Resume current music.

Returns:

Boolean:

resumeSound

(
  • id
)
Boolean

Resume sound.

Parameters:

  • id Number

    Id of sound

Returns:

Boolean:

Return false, if sound is not paused

setMusicVolume

(
  • value
)

Change main music volume.

Parameters:

  • value Number

setPlaybackRate

(
  • id
  • rate
)

Change audio playback rate (Web Audio).

Parameters:

  • id Number
  • rate Number

setSoundVolume

(
  • value
)

Change main sound volume.

Parameters:

  • value Number

setVolume

(
  • id
  • value
)

Set volume for specific audio.

Parameters:

  • id Number
  • value Number

stopMusic

() Boolean

Stop current music.

Returns:

Boolean:

stopSound

(
  • [id]
  • [skipCallback]
)
Boolean

Stop specific or all sounds.

Parameters:

  • [id] Number optional

    Id of sound

  • [skipCallback] Boolean optional

    Skip callback function

Returns:

Boolean:

toggleMusic

() Boolean

Toggle music on/off.

Returns:

Boolean:

toggleSound

() Boolean

Toggle sounds on/off.

Returns:

Boolean:

unmuteMusic

()

Unmute current music.

unmuteSound

(
  • [id]
)
Boolean

Unmute specific sound or all sounds.

Parameters:

  • [id] Number optional

    Id of sound

Returns:

Boolean:

Properties

currentMusic

Number

Current music id.

currentMusicName

String

Name of current music.

formats

Array

List of supported audio formats.

musicMuted

Boolean

Is music muted.

Default: false

pausedSounds

Array

List of paused sounds.

playingSounds

Array

List of playing sounds.

soundMuted

Boolean

Is sounds muted.

Default: false

Attributes

enabled

Boolean

Enable audio.

Default: true

formats

Array

List of available audio formats.

musicVolume

Number

Music volume.

Default: 1

soundVolume

Number

Sound volume.

Default: 1

stopOnSceneChange

Boolean

Stop audio, when changing scene.

Default: true

webAudio

Boolean

Enable Web Audio.

Default: true