Background Music

The BackgroundMusic class can be used to control the Background Music of a UI Screen Node.

Static Function Description
play(sound, looped)

Sets the audio track of the Background Music and plays it.

stop()

Stops the Background Music.

setVolume(volume)

Sets the volume of the Background Music, range 0 (muted) to 1 (max).

volume()

Returns the volume of the Background Music, range 0 (muted) to 1 (max).


play(sound, looped)

Sets the audio track of the Background Music and plays it.

Parameters

Sound sound – The new audio to play as Background Music. Sound is a Script node attribute.
boolean looped – Optional. Set the Background Music to loop if true, or stop after one play if false.

function start(){
     let track2 = this.attribute('track2');
     BackgroundMusic.play(track2);
}


A screenshot showing the Sound attribute used in the code example.

↑ Back to top


stop()

Stops the Background Music.

↑ Back to top


setVolume(volume)

Sets the volume of the Background Music, range 0 (muted) to 1 (max).

Parameters

number – the new volume of the Background Music

↑ Back to top


volume()

Returns the volume of the Background Music, range 0 (muted) to 1 (max).

Returns

number – the volume of the Background Music

↑ 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?