iosswiftsprite-kitskemitternode

iOS SpriteKit Emitter particle frequency


Is it possible to change how often a particle is emitted. For example, if I have one particle emitting, can I have it emit every 5 or 10 seconds?

I searched the documentation, but could not find anything. Is there a workaround? I would like to do something like this:

   emitter.particleBirthRate = 1
   emitter.particleBirthRateFrequency = 5  // this does not exist

Solution

  • I stay away from timers, there really isn't a need for them in SpriteKit

    You have a built in timer function with the update func, or you can Just use actions to control your time.

    what you are probably looking for is particle.resetSimulation()

    I would do what you need to do like so

    you can also put a key on your action and stop it by key name whenever needed

    if let spark = self.childNode(withName: "sparkin") as? SKEmitterNode {
        
        self.spark = spark
    
        //set time here to how long in between restarting the emitter
        let waiter = SKAction.wait(forDuration: 5)
        let resetter = SKAction.run( { self.spark.resetSimulation() } )
        let seq = SKAction.sequence([waiter, resetter])
        let repeater = SKAction.repeatForever(seq)
        run(repeater)
    }