【问题标题】:Sound for Scene Transition, that doesn't stutter场景过渡的声音,不会卡顿
【发布时间】:2016-11-21 15:59:12
【问题描述】:

在 SpriteKit(对于那些不熟悉它的人)中,有一种加载和卸载场景的方法,以及它们之间的过渡(视觉)。

我正在尝试在场景之间进行声音播放,因为它们会过渡...不会卡顿。

到目前为止,我尝试过的所有方法要么不发出声音,要么声音断断续续,甚至使用声音管理器,如下所示:

import AVFoundation
import SpriteKit

open class SoundManager {

    static let soundStart = SKAction.playSoundFileNamed("ActionBeep_AP1.7", waitForCompletion: true)


    static var coinSound = NSURL(fileURLWithPath:Bundle.main.path(forResource: "ActionBeep_AP1.7", ofType: "wav")!)
    static var audioPlayer = AVAudioPlayer()
    open static func playCoinSound(){
        guard let soundToPlay = try? AVAudioPlayer(contentsOf: coinSound as URL) else {
            fatalError("Failed to initialize the audio player with asset: \(coinSound)")
        }
        soundToPlay.prepareToPlay()
        self.audioPlayer = soundToPlay
        self.audioPlayer.play()
    }


}

有人成功地让场景过渡声音流畅运行吗?我意识到在场景过渡期间发生了很多事情,这可能对声音引擎没有帮助。但是认为必须有一种方法可以在场景转换期间播放清晰的声音。

是的,我尝试过使用 .caf、.mp3 和 .wav 文件,它们都具有不同的“压缩”和原始状态。我认为问题在于我播放声音的方式,而不是文件类型。

【问题讨论】:

标签: swift audio avfoundation skscene


【解决方案1】:

正如 crashoverride777 所说,您需要在加载声音管理器时进行更改。您可以在 didMoveToView() 函数中设置一个线程来最小化加载时间:

DispatchQueue.global(qos: .userInitiated).async {
  // Load your sound stuff
}

现在,您可以随时加载声音文件,无延迟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    相关资源
    最近更新 更多