Hi there,
I want that my spaceship gets louder when my mouse moves away from it (and vice versa). Problem is that my function produces an annoying crackling sound I can't get rid of when I move my mouse away from it (and vice versa). The sound file is ok so far. Can someone help me out with this problem, please?
Code:
shipSpeed = (abs(player.x - playerPrevPt.x) + abs(player.y - playerPrevPt.y)) / 2;//the ship's speed gets calculated
//this is used to determine whether the ship's volume of its sound shall be increased or decreased
if (shipSpeedPrev < shipSpeed) {
sndManager.increaseSound(Main.SOUND_BACKGROUND, false, .01);
} else if (shipSpeedPrev > shipSpeed) {
sndManager.decreaseSound(Main.SOUND_BACKGROUND, false, .01);
} else if (shipSpeedPrev == shipSpeed) {
} else {
}
shipSpeedPrev = (abs(player.x - playerPrevPt.x) + abs(player.y - playerPrevPt.y)) / 2;//this is another ship speed so I can compare them
//the decreseSound-function is almost the same
Code:
public function increaseSound(soundName:String, isSoundTrack:Boolean = false, steps:Number = .1, targetVol:Number = 1):void {
if (isSoundTrack) {
if (soundTrackChannel != null) {
musicVolumeAdj.volume += steps;
if (musicVolumeAdj.volume >= targetVol) {
musicVolumeAdj.volume = targetVol;
}
soundTrackChannel.soundTransform = musicVolumeAdj;
}
} else {
soundVolumeAdj = new SoundTransform(incrSndVal, 0);
incrSndVal += steps;
soundVolumeAdj.volume += incrSndVal;
if (soundVolumeAdj.volume >= 1) {
soundVolumeAdj.volume = 1;
}
soundChannels[soundName].soundTransform = soundVolumeAdj;
//trace("soundVolumeAdj.volume " + soundVolumeIncrAdj.volume);
}
}