0

I have created a template particle file in my project and want to use it with different texture images.

I have created this and use this method...

func addEmitterWithTexture(image: UIImage, size: CGSize, advanceTime: NSTimeInterval, scene: SKScene) {
    let emitter = SKEmitterNode(fileNamed: "MyParticle")!
    scene.addChild(emitter)
    emitter.particleTexture = SKTexture(image: image)
    emitter.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
    emitter.particlePositionRange = CGVector(dx: size.width, dy: size.height)
    emitter.advanceSimulationTime(advanceTime)
    emitter.zPosition = 3.0
}

I would like the images to pop in at different times so I use the advanceSimulationTime. But it doesn't seem to have an effect. All the images use the same simulation time.

I'm guessing this is because the simulation time is on the parent?

Edit Hmm... that doesn't seem to be the case.

I wonder if all the emitters are on a global simulation timer? In that case, is there any way to start the emitters at different times?

Is that the case or am I doing something wrong?

I got around it in the end by using a waitAction on the scene and adding the emitters in a runBlock action after the wait.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • all emitters run on their own time when they are started – Knight0fDragon Aug 15 '16 at 14:09
  • @Knight0fDragon that's what I assumed but it wasn't updating them individually. I had to add them at different times to get the effect I wanted. Advancing the simulation time only put them all forward by the same amount. This is a scene inside an SKView in a non-SpriteKit app so maybe that affected something? – Fogmeister Aug 15 '16 at 14:12
  • I am writing an answer for you – Knight0fDragon Aug 15 '16 at 14:13
  • no such thing as `SpriteKit app`, If you have a SKView and are dealing with SKScene, then you are dealing with sprite kit, regardless of the template you started with – Knight0fDragon Aug 15 '16 at 14:14
  • @Knight0fDragon ah, ok. Fair enough. Will wait for your answer :) – Fogmeister Aug 15 '16 at 14:15

1 Answers1

0

The only thing that advance time does is fast forward the emitter action forward in time, do not use this when you want emitters to fire at different times, before you add the emitter to your scene, stop it by setting paused to true, particleSpeed to 0 and calling resetSimulation() This guarentees us that when the particle emitter is added it will not run. Then use SKAction's to determine when you need to unpause the emitter and set its speed back to its default speed

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44