Sound:fade([from], [to], [duration])method
Gradual increase (fade out) or decrease (fade in) the volume of the sound over a period of time
Parameters
[from]
A number representing the starting volume. A value of 0.0 (the default) means silence. The special value -1 means the current volume
[to]
A number representing the ending volume. A value of 1.0 (the default) means maximum volume without amplification.
[duration]
A number representing the duration of the fade effect in milliseconds. The default value is 1000 (1 second).
Return value
This function returns no value.Example
--! luart-extensions
import audio
-- Loads and play a music
local sound = audio.Sound("music.mp3")
-- fade out the sound volume for 3 second
sound:fade(0, 1, 3000)
sound:play()
sleep(3000)
-- fade in the sound for 2 second
sound:fade(1, 0, 2000)
-- let the sound play until fade out effect is terminated
sleep(2000)