在我的MenuScene.swift中,当我的游戏开始时,我有一系列随机播放的声音:
let soundNames = [
"Sound/01.mp3",
"Sound/02.mp3",
"Sound/03.mp3"
]
let randomSoundName = soundNames[Int(arc4random_uniform(UInt32(soundNames.count)))]
_ = self.run(SKAction.playSoundFileNamed(randomSoundName, waitForCompletion: false))
...在我的GameViewController.swift中,我有一个随着游戏开始播放的背景音轨:
// Start the background music:
if let musicPath = Bundle.main.path(forResource:
"Sound/BackgroundMusic.wav", ofType: nil) {
let url = URL(fileURLWithPath: musicPath)
do {
musicPlayer = try AVAudioPlayer(contentsOf: url)
musicPlayer.numberOfLoops = -1
musicPlayer.prepareToPlay()
musicPlayer.play()
}
catch { /* Couldn't load music file */ }
}
当随机声音在其顶部播放时,如何减小背景音轨的音量?