Instance Method

advanceSimulationTime:

Advances the emitter particle simulation.

Declaration

- (void)advanceSimulationTime:(NSTimeInterval)sec;

Parameters

sec

The number of seconds to simulate.

Discussion

Once added to a scene, an emitter node automatically creates new particles in new animation frames. This method allows you to artificially advance a running emitter’s simulation, causing it to generate new particles and advance any existing particles. The most common use for this method is to prepopulate an emitter node with particles after it is first added to a scene.

If an emitter is paused, either directly or by one of its parent nodes being paused, advanceSimulationTime: has no effect. Listing 1 shows how to advance an emitter object while it is paused, by temporarily toggling its paused property while advancing the simulation.

Listing 1

Temporarily unpausing an emitter to advance simulation time

let emitter = SKEmitterNode()
let emitterPaused = emitter.isPaused
if emitterPaused {
    emitter.isPaused = false
}
emitter.advanceSimulationTime(5)
if emitterPaused {
    emitter.isPaused = true
}

Note that the paused property is inherited from a node’s parents, so even if the emitter hasn’t been explicitly paused but, for example, the scene has, this code will still work.

See Also

Controlling When Particles Are Created

- resetSimulation

Removes all existing particles and restarts the simulation.

particleBirthRate

The rate at which new particles are created.

numParticlesToEmit

The number of particles the emitter should emit before stopping.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software