Sound

Sound Functions

We have two categories for audio functions. Sound functions are for short sound clips like sound effects. Music functions are intended for longer music clips

loadSound

Async. Loads a sound clip from a disk file.

name
type
default
description

file*

file

-

the file that contains the sound clip

volume

number

1

a number between 0.0 and 1.0 that indicates what volume to use for this sound clip.

Returns

object a sound that you can pass to the playSound function (see below)

world.beep = await loadSound(require("./beep.wav"))
world.soundtrack = await loadSound(require("./funkybeat.wav", 0.3))

playSound

Plays a sound clip on your computer speakers.

name
type
default
description

sound*

object

-

the sound clip to play (must have been already loaded by the loadSound function)

repeat

boolean

false

a boolean indicating whether to repeat the sound forever or just play it once.

Returns

nothing

playSound(world.beep)
playSound(world.soundtrack, true))

stopSound

Stops a sound clip from playing.

name
type
default
description

sound*

object

-

the sound clip to stop

Returns

nothing

stopSound(world.soundtrack)

loadMusic

Loads a music clip from a disk file so that you can play it later using the playMusic function. Only one music clip may be loaded at a time. This supports MP3 and some other music file formats.

name
type
default
description

file*

file

-

the file that contains the music clip

volume

number

1

a number between 0.0 and 1.0 that indicates what volume to use for this music clip.

Returns

nothing

loadMusic(require("./themesong.mp3"))

playMusic

Plays the music clip that you loaded with the loadMusic function. Only one music clip can be playing at once.

name
type
default
description

repeat

boolean

false

a boolean indicating whether to repeat the music forever or just play it once.

Returns

nothing

playMusic()
playMusic(true)

stopMusic

Stops the current music from playing.

Returns

nothing

stopMusic()

Last updated