I was wondering how I would go about slowly fading out music.
The music starts playing from Room120 and then slowly fades out at Room122.
I know how to make a loop to fade things out, but do I define a global variable to the volume of an audio track?
Here is how:
First declare a global variable (in my case Volume) set it to 100 which is the default for music master volume.
Then in the room's script:
function room_RepExec()
{
if (Volume > 0)
{
Volume -= 1;
SetMusicMasterVolume(Volume);
}
if (Volume == 0)
{
StopMusic();
SetMusicMasterVolume(100);
}
}
======================
This will make it fade out in 100 game loops or 2.5 seconds to make it fade out even slower put this in.
======================
function room_RepExec()
{
if (Volume > 0)
{
SetTimer(1, 1);
//Remember that whatever you put in for the timer will be run 100 times so the
//Number should be small-ish
Volume -= 1;
}
if (IsTimerExpired(1) == true)
{
SetMusicMasterVolume(Volume);
}
if (Volume == 0)
{
StopMusic();
SetMusicMasterVolume(100);
}
}
Hope that works!