Game Development Reference
In-Depth Information
NSBundle.mainBundle().pathForResource("MySparkParticle",
ofType: "sks")
let emitter =
NSKeyedUnarchiver.unarchiveObjectWithFile(pathToEmitter!)
as? SKEmitterNode
addChild(emitter!)
This is the most common process of creating and adding particle emitters to your game.
Let's take a look at the properties that will be used in the SuperSpaceMan game.
The Particle Life-Cycle Properties
The particle life-cycle properties determine how many particles are created, the maximum
number of particles that can be created, and the lifetime of each of the created particles.
There are four properties that control the life cycle of a particle, as shown in Figure 6-6 .
Figure 6-6 . The Sprite Kit particle life-cycle properties
The Birthrate and Maximum Properties
The first two life-cycle properties are the Birthrate and Maximum properties. The Bir-
thrate property defines the rate at which new particles are emitted per second. The higher
the value, the faster new particles are generated.
The Maximum particle life-cycle property determines the total number of particles to be
emitted by the emitter. A value of 0 causes particles to be emitted indefinitely. Any other
value will cause the emitter to stop emitting when that value is reached.
To see how these two properties work together, go back to the SpriteKit Particle Emitter
properties editor in Xcode and change the Birthrate property to 20 and change the Maxim-
um property to 0. Watch what happens—the emitter generates 20 particles per second.
Now leave the Birthrate property at 20, change the Maximum property to 20, and check
out how the emitter changes. This time, the emitter will emit 20 particles over 1 second
Search WWH ::




Custom Search