控制球员的体积 - 噼啪声

时间:2012-03-13 21:49:49

标签: actionscript-3 audio

当我的鼠标远离它时,我希望我的飞船能够响亮(反之亦然)。问题是我的功能会产生恼人的噼啪声,当我将鼠标移开时,我无法摆脱它(反之亦然)。声音文件到目前为止还可以。有人可以帮我解决这个问题吗?

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

// decreaseSound函数几乎相同

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;
        }
    }

1 个答案:

答案 0 :(得分:1)

当您增加音量时,音频最有可能最终为clipped。尝试找出剪辑发生的音量,然后更改你的功能,使其不超过该音量。

也许你也可以重新创作音频文件并降低整体音量,这样你就可以从游戏中增加音量。