本文介绍了场景过渡的声音,不会结结巴巴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In SpriteKit (for those unfamiliar with it) there's a way to load and unload scenes, and a transition (visual) between them.

我正在尝试在场景之间播放声音,因为它们过渡时...不会结巴.

I'm trying to make a sound play between scenes, as they transition... that doesn't stutter.

到目前为止,即使使用声音管理器,我尝试过的所有方法都不会产生声音,也不会发出声音结结巴巴,例如:

So far, all the ways I've tried either create no sound, or the sound stutters, even using a sound manager, like this:

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()
    }


}

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

Anyone had any success making scene transition sounds run smoothly? I realise there's a lot going on during a scene transition, and that's probably not helping the sound engine. But think there must be a way to make a clear sound play during a scene transition.

是的,我尝试使用.caf,.mp3和.wav文件,它们都具有不同的压缩"和原始状态.我认为这是我播放声音的方式,而不是文件类型.

And yes, I've tried with .caf and .mp3 and .wav files, all with different "compression" and raw states. I think it's how I play the sounds that's the problem, not the file type.

推荐答案

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

As crashoverride777 said, you need to change when you load the sound manager. You could set up a thread in your didMoveToView() function to minimize loading time:

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

现在,您可以随时随地加载声音文件,而不会出现延迟.

Now, you have your sound file loaded for whenever you need it, lag-free.

这篇关于场景过渡的声音,不会结结巴巴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 06:54