我想一次播放多个声音。我像这样使用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)
}
答案 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])