Why is Add Emitter to Node not happening immediately?
Within an extension to GameViewController
I have:
func addEmitterToNode(_ particleName: String,
_ theNode:SKSpriteNode) {
if let emitter = SKEmitterNode(fileNamed: particleName) {
emitter.name = "emitter"
emitter.position = CGPoint(x: 0, y: 0) // = at center
theNode.addChild(emitter)
}
} // addEmitterToNode
Here is the func
(extension to GameViewController
) wherein I call the above. The problem is the explosion sound plays but the smoke particle emitter is not immediately added.
func increaseSpeed() {
if thisSpeed > maxSpeed {
pauseGame() // sets myTrain.isPaused = true
playSound(theSoundName: "explosion")
addEmitterToNode("smokeParticle.sks", myTrain)
trainHasCrashed = true
}
} // increaseSpeed
What I do not understand is that the following within GameScene's sceneDidLoad
, the smoke particle emitter is added =
override func sceneDidLoad() {
if itsGameViewController.trainHasCrashed {
itsGameViewController.addEmitterToNode("smokeParticle.sks",
myTrain)
}
}