Sound

The Sound Node plays an mp3 file.

Function Description
isPlaying()

Returns true if the sound is currently playing, false if not.

setVolume(value)

Sets the volume of the sound, from 0-1. The sound must already be playing before you set the sound with this function, and must be looped or non-overlapping.

volume()

Returns the volume of the sound if it is playing, from 0-1.


isPlaying()

Returns true if the sound is currently playing, false if not.

Returns

boolean – true if the sound is playing, false if not

↑ Back to top


setVolume(value)

Sets the volume of the sound, from 0-1. The sound must already be playing before you set the sound with this function, and must be looped or non-overlapping.

Parameters

number value – the volume of the sound

↑ Back to top

let fadein = false;
let mySound;
let volume = 0;

function start() {
	// start the fade in at the start of the scene
	fadein = true;
	mySound = this.entity().component("My Sound");
}

function update(dt) {
	// stops adjusting volume once volume goes over 1
	if (fadein && volume <= 1) {
		// check if the sound is playing
		if (mySound.isPlaying()) {
			// set the volume, and then increase the volume for the next update loop
			mySound.setVolume(volume);
			volume += 0.001;
		}
	}
}

volume()

Returns the volume of the sound if it is playing, from 0-1.

Returns

number - the volume of the sound

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?