There are different ways to get this working, if you want to use SKAudioNode then you could do the following.
Near the top of the GameScene file, create a variable:
var audio = SKAudioNode()
In "didMove(to view: SKView)" add the below lines:
audio = SKAudioNode(fileNamed: "clink.wav")
audio.autoplayLooped = false
addChild(audio)
In your function (which gets called in your didBegin(_ contact: SKPhysicsContact)), put the below lines in:
let playAction = SKAction.play()
let wait = SKAction.wait(forDuration: 1.0)
let grp = SKAction.group([playAction, wait])
let rfp = SKAction.removeFromParent()
let sequence = SKAction.sequence([grp, rfp])
audio.run(sequence)
Typically, you wouldn't need such an approach, but SKAction.play() doesn't seem to work with the completion: block, therefore i had to include a duration of 1 second (which is what you were happy doing before).
That should work.
Another approach, which is simpler, is:
var audio: SKAction?
Then in didMove(to view) put:
audio = SKAction.playSoundFileNamed("Clink.wav", waitForCompletion: false)
Then in your function just put this:
self.run(audio!, completion: {
self.removeFromParent()
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…