I've included a bit of code in a room which manually animates an object, and plays 'linked' sounds for each frame; it then adjust the volume depending on the players position and closeness to the object.
The sounds are played at full volume for the first second; what should I do to keep the sound consistent?
function SoundDistDS(int x, int y, int radius, int minVolume)
{
int Volume=0;
int dx = 610 - x; //hard coded in pos of darkseeds sign
int dy = 515 - y;
int d_squared = dx*dx + dy*dy;
if(d_squared >= (radius * radius))
Volume = minVolume;
else
Volume = FloatToInt(100.0 - (Maths.Sqrt(IntToFloat(d_squared))/IntToFloat(radius)) * (100.0 - IntToFloat(minVolume)));
return Volume;
}
function PlaySoundDS(int animFrame)
{
switch (animFrame) {
case 0: ds_chan=aNeon_1.Play(eAudioPriorityNormal, eOnce);break;
case 1: ds_chan=aNeon_2.Play(eAudioPriorityNormal, eOnce);break;
case 2: ds_chan=aNeon_1.Play(eAudioPriorityNormal, eOnce);break;
case 3: ds_chan=aNeon_2.Play(eAudioPriorityNormal, eOnce);break;
case 4: ds_chan=aNeon_1.Play(eAudioPriorityNormal, eOnce);break;
case 5: ds_chan=aNeon_2.Play(eAudioPriorityNormal, eOnce);break;
case 6: ds_chan=aNeon_1.Play(eAudioPriorityNormal, eOnce);break;
case 7: ds_chan=aNeon_2.Play(eAudioPriorityNormal, eOnce);break;
case 8: ds_chan=aNeon_1.Play(eAudioPriorityNormal, eOnce);break;
case 9: ds_chan=aNeon_2.Play(eAudioPriorityNormal, eOnce);break;
case 10: ds_chan=aNeon_3.Play(eAudioPriorityNormal, eOnce);break;
case 11: break;
case 12: break;
case 13: break;
}
ds_chan.Volume=SoundDistDS(cJulius.x, cJulius.y, 300, 3);
}
function late_repeatedly_execute_always()
{
//Display("wa %d, yctr %d", wa, yctr);
wa++;
if (wa>20) {
wa=0;
yctr++;
if (yctr>13)
yctr=0;
ViewFrame *vf;
vf=Game.GetViewFrame(10, 0, yctr);
oDarkSeedsSign.Graphic=vf.Graphic;
PlaySoundDS(yctr);
}
}
function room_Load()
{
...
oDarkSeedsSign.SetView(10);
wa=0;//global
yctr=0;//global
...
}
Have you try to use AudioChannel.SetRoomLocation?