SKAction.playSoundFileNamed()导致高内存崩溃

时间:2015-11-19 12:08:26

标签: swift sprite-kit avaudioplayer skaction

我想一次播放多个声音。我像这样使用SpriteKit SKAction

SKAction.playSoundFileNamed("aa.wav", waitForCompletion: true)

我发现应用程序在内存使用量增加时崩溃。

  • 我尝试了SKAudioNode,但没有提供非常好的表现。
  • 我尝试了AVAudioPlayer,但我不知道如何在一个声音中播放多个声音 时间AVAudioPlayer

以下是错误:

代码:

  static func palyBulletAttackedSound(node:SKNode)
    {
        if(isSound)
        {

            let bulletSoundAction =   SKAction.playSoundFileNamed("LichMissileHit2.wav", waitForCompletion: true)
            if(node.actionForKey("sound")==nil)
            {
                node.runAction(bulletSoundAction, withKey: "sound")                            }
          }
    }

更新

 let bulletSoundAction = SKAction.playSoundFileNamed("LichMissileHit2.wav", waitForCompletion: false)
    func bulletUpdate(currentTime:CFTimeInterval)
    {
         ……
         //SoundUtil.palyBulletAttackedSound(map)
         map.runAction(bulletSoundAction)

    }

2 个答案:

答案 0 :(得分:0)

要一次播放多个声音,请使用waitForCompletion: false代替waitForCompletion: true

Scene中这样做:

self.runAction.SKAction.playSoundFileNamed("aa.wav", waitForCompletion: false)

答案 1 :(得分:0)

你知道你可以并行运行行动吗?

let action1 = SKAction.playSoundFileNamed(one.mp3, waitForCompletion: false)
let action2 = SKAction.playSoundFileNamed(two.mp3, waitForCompletion: false)
node.runAction(SKAction.group([action1, action2])