2

I am currently preloading sound effects in a dictionary, as such:

soundEffectsDictionary[SoundEffectType: SKAudioNode]

Doing this allows me to preload all the sound effects in the game, and request a sound effect as needed. I am simplifying this for demonstration purposes:

let fxBoom = soundEffectsDictionary[SoundEffectType.fxBoom]!.copy() as! SKAudioNode

This works in the same way for SKSpriteNodes, SKTextures, etc. However, it does not seem that SKAudioNode can produce copies in this way. When I try to add the copies to the screen, they do not play.

  1. How can I properly copy SKAudioNode? If I want to play fxBoom twice, overlapping, then I will need two separate nodes. I do not want to load the file from disk for performance reasons, which is why I'm attempting to preload the sounds.

  2. Is there a better way to achieve what I am trying to do here?

Thanks in advance.

EDIT:

Here is some simple code that demonstrates the issue:

    let audioNode = SKAudioNode(fileNamed: "fxBoom.mp3")
    self.addChild(audioNode) //audio plays, looping indefinitely


    let audioNode = SKAudioNode(fileNamed: "fxBoom.mp3")
    let audioNode2 = audioNode.copy() as! SKAudioNode
    self.addChild(audioNode2) // audio does not play
    audioNode2.run(SKAction.play()) // no difference
    audioNode2.isPaused = false // no difference
MikeL
  • 163
  • 10

0 Answers0