Skip to content

Docs Module Sound

Carlonn Rivers edited this page Sep 6, 2021 · 9 revisions

Sound

Handles sound clips and gets sound instances from the engine's library.

Properties

Property Description Type Default
type The flobtive's description type. readonly
_volume The master volume of all sound clips. number 100

Event Summary

Event Description
onError() Handler for all sound errors. Passes the error message as its first parameter.

SoundClips

A sound clip is obtained by calling the Sound module with the sound clip's name as the first parameter: Sound("mySound")

Properties

Property Description Type Default
type The flobtive's description type. readonly
hasLoaded A value that indicates whether the sound clip has been loaded or not.
readonly
boolean
_volume The volume of the sound clip. number 100
_loop A value that indicates whether the sound clip should start over again when finished. boolean false
_time The current playback position of the sound clip in seconds. number 0
_paused A value that indicates whether the sound clip is paused or not.
readonly
boolean true
_muted A value that indicates whether the sound clip is muted or not.
readonly
boolean false
_duration The length of the sound clip in seconds.
readonly
boolean

Method Summary

Method Description
*duplicate() Duplicates the sound clip and adds it to the library, returning a reference to the duplicated sound clip.
seekBackward() Carries the sound clip's current time backwards by a specified amount of seconds.
seekForward() Carries the sound clip's current time forwards by a specified amount of seconds.
mute() Mutes the sound clip.
pause() Pauses the sound clip.
*play() Starts or resumes the playing of the sound clip.
*playClone({ _volume, onend }) Creates and plays a unique instance of the sound clip.
Is automatically deleted when ended.
*playLoop() Plays the sound clip on loop.
Sets sound clip's loop property to true.
*playOnce() Resets current time and plays the sound clip once.
Sets sound clip's loop property to false.
*restart() Restarts the sound clip.
stop() Resets the current time and stops the playing of the sound clip.
unmute() Unmutes the sound clip.

* methods are asynchronous, and should be called by appending await to the left of the method, within async functions.

Methods

duplicate()

Duplicates the sound clip and adds it to the library, returning a reference to the duplicated sound clip.

An asynchronous method.

Usages

  • duplicate(name, config)
  • duplicate(name)

Parameters

  • name
    • Type: string The name of the duplicated sound clip. Must be unique to other sound names.
  • config
    • Type: object

    • Sound configurations.

    • Values:

      Property | Description | Type --: | --- | --- | --- _volume | The audio clip's default volume. | number _loop | The audio clip's loop property. | boolean

    • Default config properties of the duplicated sound clip are the values of the original sound clip.

Examples

Assuming const mySound = Sound("mySound"); and we want to duplicate mySound to create mySound2 that keeps all mySound's properties.

/* Within scene's async onload */

const mySound2 = await mySound.duplicate("mySound2");

If we want to duplicate mySound to create mySound3 using different properties:

/* Within scene's async onload */

const mySound3 = await mySound.duplicate("mySound3", { _volume: 20 });

seekBackward(time)

Carries the sound clip's current time backwards by a specified amount of seconts.

Parameters

  • time
    • Type: integer
    • The number of seconds by which to carry back the sound clip's current time.

Example

Assuming const mySound = Sound("mySound"); and the current time is 10 seconds (mySound._time = 10).

Carry the time backward by 4 seconds:

/* Within scene's onload */

mySound.seekBackward(4);
// mySound._time == 6

seekForward(time)

Carries the sound clip's current time forwards by a specified amount of seconts.

Parameters

  • time
    • Type: integer
    • The number of seconds by which to carry forward the sound clip's current time.

Example

Assuming const mySound = Sound("mySound"); and the current time is 6 seconds (mySound._time = 6).

Carry the time forward by 4 seconds:

/* Within scene's onload */

mySound.seekForward(4);
// mySound._time == 10

play()

Starts or resumes the playing of the sound clip.

An asynchronous method.

Example

Assuming a sound clip called "mySound" exists in the engine's library:

Play sound clip.

/* Within scene's async onload */

await Sound("mySound").play();

Assuming const mySound = Sound("mySound");

Play sound clip.

/* Within scene's async onload */

await mySound.play();

*(Working Draft)