This is one of those occasions I really hate the new AGS sound system. You used to just be able to play a new tune and it would automatically fadein and fadeout, but no longer.

Anyway, enough griping!
I discovered that Edmundo's lovely tweening module can tween the volume of audio channels, WITHOUT blocking. This is ideal, since I can fadein/fadeout between music and ambient sound without stopping the action.
I have three audio channels: MusicChannel, MusicChannelb and MusicChannelActive.
How it works is I start playing music on MusicChannel, then switch over to MusicChannelb (using the tween module to fade up the volume of one while fading down the volume of the other) and then setting MusicChannelActive to the new channel. I also have a silent music clip called aSilence that I use when I want to turn off the sound.
Here's the function declaration:
Code: AGS
And here's the juicy code:
Code: AGS
At game_start, everything is set to these values:
Code: AGS
The result of all this nonsense? It works... half the time. Half the time, the music doesn't change at all. Once in a while, the music doesn't even begin at the start of the game. It seems totally arbitrary and I have been spending ages trying to sort out why. So... help? What am I doing wrong? Or is there a much better way of doing this entirely?
Thanks in advance!
-Dave


Anyway, enough griping!
I discovered that Edmundo's lovely tweening module can tween the volume of audio channels, WITHOUT blocking. This is ideal, since I can fadein/fadeout between music and ambient sound without stopping the action.
I have three audio channels: MusicChannel, MusicChannelb and MusicChannelActive.
How it works is I start playing music on MusicChannel, then switch over to MusicChannelb (using the tween module to fade up the volume of one while fading down the volume of the other) and then setting MusicChannelActive to the new channel. I also have a silent music clip called aSilence that I use when I want to turn off the sound.
Here's the function declaration:
import function MusicChange(AudioClip*thisclip, int vol=50, int time=500, bool repeat=true);
And here's the juicy code:
function MusicChange(AudioClip*thisClip, int vol, int time, bool repeat)
{
float ftime=IntToFloat(time);
ftime=ftime/1000.0;
if (MusicChannelActive.PlayingClip != thisClip) //check to see if the active channel is already playing the requested clip
{
if (MusicChannelActive==MusicChannel) //switch to musicChannelB
{
if (repeat==true)
MusicChannelb = thisClip.Play(eAudioPriorityVeryHigh, eRepeat);
else
MusicChannelb = thisClip.Play(eAudioPriorityVeryHigh, eOnce);
MusicChannelb.Volume=0;
MusicChannelb.TweenVolume(ftime, vol, eLinearTween, eNoBlockTween);
MusicChannel.TweenVolume(ftime, 0, eLinearTween, eNoBlockTween);
MusicChannelActive=MusicChannelb;
}
else if (MusicChannelActive==MusicChannelb) //switch to music channel A
{
if (repeat==true)
MusicChannel = thisClip.Play(eAudioPriorityVeryHigh, eRepeat);
else
MusicChannel = thisClip.Play(eAudioPriorityVeryHigh, eOnce);
MusicChannel.Volume=0;
MusicChannel.TweenVolume(ftime, vol, eLinearTween, eNoBlockTween);
MusicChannelb.TweenVolume(ftime, 0, eLinearTween, eNoBlockTween);
MusicChannelActive=MusicChannel;
}
}
}
function repeatedly_execute_always()
{
if (MusicChannelActive == MusicChannel && MusicChannelb.Volume==0)
MusicChannelb.Stop();
if (MusicChannelActive == MusicChannelb && MusicChannel.Volume==0)
MusicChannel.Stop();
}
At game_start, everything is set to these values:
MusicChannel = aSilence.Play(eAudioPriorityNormal, eRepeat);
MusicChannelb = aSilence.Play(eAudioPriorityNormal, eRepeat);
MusicChannel.Volume=100;
MusicChannelb.Volume=0;
MusicChannelActive=MusicChannel;
The result of all this nonsense? It works... half the time. Half the time, the music doesn't change at all. Once in a while, the music doesn't even begin at the start of the game. It seems totally arbitrary and I have been spending ages trying to sort out why. So... help? What am I doing wrong? Or is there a much better way of doing this entirely?
Thanks in advance!
-Dave