Reputation: 586
I have decided to break off my very painful relationship with SKAction.playSoundFileNamed and move on to using SKAudioNodes in our project -- the breaking point was their being totally broken by interruptions without any consistency.
We are trying to create an extension to SKAction s.t. it will mimic playing SKAudioNodes without adding delay, similar to when you set the waitForCompletion property in playSoundFileNamed to false. However, we are adding the SKAudioNode and then disposing of it after a short period (3.0 s), but in an extension this would add that 3.0 s delay onto any action. I think we must have this delay and then remove because otherwise we would be accumulating SKAudioNodes unnecessarily. Here is our current code:
func playAudioNode(node: SKSpriteNode?, sound: SoundType, delay: Double)
{
if node == nil
{
return
}
let audioNode = audioNodeDictionary[sound]!.copy() as! SKAudioNode
node!.addChild(audioNode)
let playSound = SKAction.run
{
audioNode.run(.play())
}
node!.run(SKAction.sequence([SKAction.wait(forDuration: delay), playSound, SKAction.wait(forDuration: 3.0), SKAction.removeFromParent()]))
}
Does anyone use SKAudioNodes in a similar ad hoc way and use them in SKAction sequences and have any thoughts on best way to implement this?
Upvotes: 5
Views: 150