Game Development Reference
In-Depth Information
Gravity mode uses the following exclusive properties, which can be used only when
emitterMode is set to kCCParticleModeGravity :
self.sourcePosition = CGPointMake(−15, 0);
self.gravity = CGPointMake(−50, -90);
self.tangentialAccel = 120;
self.tangentialAccelVar = 10;
self.speed = 15;
self.speedVar = 4;
The sourcePosition determines the offset as a CGPoint from the node's position
where new particles appear. The name is a bit misleading in that the actual center of
gravity is the node's position, and sourcePosition is an offset to that center of
gravity. The gravity property then determines the speed with which particles accel-
erate in the x and y directions. In this case, the negative values indicate that the gravit-
ational force will accelerate particles toward the left (−50) and downward (−90). But
this acceleration is relative to the particle node's position. Because particles start out at
a sourcePosition offset of −15 (slightly offset to the left), they perform a counter-
clockwise movement around the particle node's position. You can see this effect in Fig-
ure 9-4 , and tweaking the values in the ParticleEffects01 project helps to understand
how sourcePosition and gravity affect the movement of particles.
For the center of gravity to have any impact, the gravity of the particles shouldn't be
too high, and the sourcePosition should not be offset too far. The previous values
give you a good working example that you can tweak.
The radialAccel property defines how fast particles accelerate the farther they
move away from the emitter. This parameter can also be negative, which makes
particles slow down as they move away. The tangentialAccel property is similar
in that it lets particles rotate around the emitter and speed up as they move away. Neg-
ative values let the particles spin clockwise, and positive values spin them counter-
clockwise.
The speed property should be fairly obvious—it's simply the speed of the particles.
It has no particular unit of measurement. Figure 9-4 shows an example particle effect
using gravity mode. Particles are attracted by the particle node's position and start out