-
Notifications
You must be signed in to change notification settings - Fork 0
Docs Module Sound
Handles sound clips and gets sound instances from the engine's library.
| Property | Description | Type | Default |
|---|---|---|---|
| type | The flobtive's description type. | readonly |
|
| _volume | The master volume of all sound clips. | number |
100 |
| Event | Description |
|---|---|
| onError() | Handler for all sound errors. Passes the error message as its first parameter. |
A sound clip is obtained by calling the Sound module with the sound clip's name as the first parameter: Sound("mySound")
| 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 | 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
awaitto the left of the method, withinasyncfunctions.
Duplicates the sound clip and adds it to the library, returning a reference to the duplicated sound clip.
An asynchronous method.
duplicate(name, config)duplicate(name)
- name
- Type:
stringThe name of the duplicated sound clip. Must be unique to other sound names.
- Type:
- 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.
-
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 });Carries the sound clip's current time backwards by a specified amount of seconts.
- time
- Type:
integer - The number of seconds by which to carry back the sound clip's current time.
- Type:
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 == 6Carries the sound clip's current time forwards by a specified amount of seconts.
- time
- Type:
integer - The number of seconds by which to carry forward the sound clip's current time.
- Type:
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 == 10Starts or resumes the playing of the sound clip.
An asynchronous method.
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)