In my game, I have a Player and a Mine. When the player hits the mine, I add an SKEmitterNode
to the scene to simulate an explosion.
In the Mine class, I declare an instance variable for the SKEmitterNode
like this:
var particles = SKEmitterNode(fileNamed: "MineExplosion")!
and when the player touches the mine, I call a function in the Mine class called explode that adds the emitterNode to the scene like this:
self.particles.position = self.position
foreGround.addChild(self.particles)
The problem is that the particles are never added to the scene. However, if I create the SKEmitterNode
inside the explosion function, then add it to the scene, the particles appear:
let particles = SKEmitterNode(fileNamed: "MineExplosion")!
particles.position = self.position
foreGround.addChild(particles)
So the only difference is declaring the SKEmitterNode
during the init of the Mine, or on the fly during the explosion function. I'd like to declare it during the init in case creating the SKEmitterNode
is what's causing my game to jitter when hitting a mine. Has anyone else experienced this?