Level up and down the sound

Hello, I am completely new to Babylon.js but I would like to test my strength and create a small project :slight_smile:
My game will be pretty much based on sounds.

In the API I did not find any information on how to turn the volume up and turn the volume down. There is only information about the volume setting, but how do I do it smoothly? I think I have to write my own function?

Welcome to the forums!

Depending on whether you want to change the volume globally or per sound, there are two functions you can call to set the volume:

AudioEngine - Babylon.js Documentation (to set the global volume)

or

Sound - Babylon.js Documentation (to set an individual sound’s volume)

Thanks for the quick reply.
I’m sorry, I did not write it down precisely enough.
I mean gradually switching from 100% to 0 in 3 seconds.

I see setVolume has 2 parameters:
newVolume: number
time: number
where time defines in how long the sound should be at this value.

I have not found a smooth change in volume anywhere.

Perhaps the description of the time parameter should clearer, but it should be doing exactly what you want already.

See Babylon.js/sound.ts at master · BabylonJS/Babylon.js · GitHub

@Bociakrodyl, Here’s a playground that you can try out to see how the volume can be modified with a given time parameter:
https://www.babylonjs-playground.com/#WU27UD

1 Like

Hey Welcome to the Babylon community!!! @PolygonalSun

Thanks a lot everybody! :slight_smile: