Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: xenogia on Fri 05/02/2010 21:34:41

Title: Slowly fading out music
Post by: xenogia on Fri 05/02/2010 21:34:41
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?
Title: Re: Slowly fading out music
Post by: Ethan D on Sat 06/02/2010 20:05:13
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!