func collisionHappened() {
let explosion = SKEmitterNode(fileNamed: "rocketExplosion")
rocket.addChild(explosion)
let sceneChange = gameOverScene(size: self.size)
sceneChange.scaleMode = scaleMode
let reveal = SKTransition.crossFadeWithDuration(3)
self.view?.presentScene(sceneChange, transition: reveal)
reveal.pausesOutgoingScene = false
}
I have attached my particle effect to the node I want to "explode" when a collision happens, thus ending the game. I then want the scene to change to the game over scene. If the outgoing scene pauses then the particle effect doesn't happen, but now I've set it to not pause, collisions keep happening and the game over scene never appears as the game keeps going back to the outgoing scene. To overcome this I thought I could add:
rocket.removeFromParent()
so that no more collisions can happen, BUT this means that the particle effect doesn't happen. Is there any way to make it so that the particle effect happens, then the rocket is removed so that I can have both?
I hope this makes sense!
If I understand your question correctly, you could add the particle effect as a child of your SKScene
subclass instead of a child of rocket
. Therefore, when you remove the rocket, the particle effect won't also be removed. Just make sure you set the SKEmitter
's position to be the rocket
's position to have the particles appear in the correct place. For example:
func collisionHappened() {
let explosion = SKEmitterNode(fileNamed: "rocketExplosion")
explosion.position = rocket.position
// I'm assuming 'self' is your SKScene subclass.
self.addChild(explosion)
let sceneChange = gameOverScene(size: self.size)
sceneChange.scaleMode = scaleMode
let reveal = SKTransition.crossFadeWithDuration(3)
self.view?.presentScene(sceneChange, transition: reveal)
reveal.pausesOutgoingScene = false
}