In my game, I have added a particle effect using SKEmitterNode that plays for a few seconds then is removed from the game.
However, when removed, the particles are left on the screen permanently.
This is the code to add and also remove the emitter:
// debrisNode is a child of scene
let emitter = SKEmitterNode(fileNamed: "shatter.sks"),
emitter.name = debrisNode.name
emitter.targetNode = scene
debrisNode.addChild(emitter)
debrisNode.run(
.sequence([
.scale(to: 0.1, duration: 1),
.run {
emitter.particleBirthRate = 0
emitter.targetNode = nil
emitter.removeAllChildren()
emitter.removeFromParent()
}]))
Edit: I now think that this is related to my use of targetNode
. When I set targetNode = debrisNode
, the particles go away - but I need targetNode to make any animation look right.