SKAudioNode completion not detected (using SKAction)

324 Views Asked by At

I need to know when an SKAudioNode has finished, but using the SKAction(:completion:) doesn't seem to work:

      audioNode.run(SKAction.play()) {

        // do something after it has finished
      }

The sound plays fine, but the thing that is supposed to execute on completion actually runs immediately.

Can someone please let me know what I´m doing wrong, and, if possible, how can I fix this?

Thank you

1

There are 1 best solutions below

2
On BEST ANSWER

One possible work-around is to force a delay. Although it works, it´s far from perfect:

let sequence = SKAction.sequence( [SKAction.play(), SKAction.wait(forDuration: soundDuration ) ])

audioNode.run(sequence, completion: {
  audioNode.removeFromParent()
})