Why is Add Emitter to Node not happening immediately?

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)
    }
 }

I just read that adding/removing SKEmitterNodes was a known issue way back in 2015. Surely, it should have been corrected by now?

Thanks to a heads-up from someone at Reddit's iOS Programming board when he asked if not pausing the SKSpriteNode made the SKEmitterNode childNode to show ...

The answer = Yes ...

So, apparently, pausing the SKSpriteNode prevents the SKSpriteNode from updating with its SKEmitterNode childNode.

I have a override to GameScene's update(_ currentTime: TimeInterval) .. but that won't be called unless the SKSpriteNode is moving.

Is there a way to pause the SKSpriteNode and force an update to display the SKEmitterNode?

FWIW, I have tried to create the SKEmitterNode first, then pause the SKSpriteNode. In this case, the SKEmitterNode will definitely show, but the SKSpriteNode does not pause.

?????

Because of the response from the programmer at Reddit, I have even tried this code:


    func  addEmitterToScene(_ particleName: String,
                            _ theScene: SKScene) {
                
        if let emitter = SKEmitterNode(fileNamed: particleName) {
            emitter.name = "emitter"
            emitter.targetNode = theScene
            emitter.position = .zero   // = at center of theScene
            theScene.addChild(emitter)
        }
        
    }   // addEmitterToScene
    
    
    func removeEmitterFromScene(_ emitterName: String,
                                _ theScene: SKScene) {
 
        if let emitterChild = theScene.childNode(withName: emitterName) {
            emitterChild.removeFromParent()
        }
        
    }   // removeEmitterFromScene

which I call via:

gameScene.addEmitterToScene("smokeParticle", itsScene)

when my Node has exceeded the speed limit

and:

gameScene.removeEmitterFromScene("emitter", itsScene)

when I start over by calling my newGame()

Same results ...

Why is Add Emitter to Node not happening immediately?
 
 
Q