Game Development Community

Audio Fade in/out

by Spinalkord · in Torque 2D Beginner · 11/17/2013 (11:40 pm) · 2 replies

Hi Guys and Gals,
What is the best way to fade Audio in and out. Currently I have this.

function levi::create(%this)
{
$soundLevel=1.0;
alxSetChannelVolume(1,1.0);
levi.playIntroSong();

}

function levi::soundFade(%this)

{

$soundLevel-=0.0091;

if($soundLevel>0.001)
       {
	echo($soundLevel);
	alxSetChannelVolume(1,$soundLevel);
	%this.schedule(30,"soundFade");
       }
else
       {
	echo("END")	;
		alxStop($introSong);
		echo("stopped Song");
		echo(alxGetChannelVolume(1));
	
	
       }
}
function levi::playIntroSong()
{
$introSong=alxPlay("levi:introMusic");

}

#1
11/18/2013 (3:59 am)
If the script you posted works, then I would say that is certainly a valid way to fade audio out. There is no built in way to do this in T2D, so a script solution like you have is the best option.
#2
11/18/2013 (6:26 am)
Note - script ticks are 32 milliseconds - scheduled times less than this are going to be at least 32 milliseconds and can occasionally cause the "flux capacitor" assert.

As far as sound fade, this isn't directly supported in OpenAL (our underlying sound handler) but if you're feeling adventurous you could add it using something like what's described in this article. It would require you to complete the implementation of positional sources (or listeners) though.