Thunk Thunk - 2 months ago 23
iOS Question

What exactly is SKEmitterNode particleLifetime?

The documentation for

says that the
property is:

The average lifetime of a particle, in seconds.

I am seeing something fishy in xcode 7.2.1, though. As I was trying to modify an explosion emitter, I expected that increasing the particle lifetime value in the editor would make the total size of the explosion bigger... the particles would live longer and thus travel farther. I don't want to increase the speed that they expand, I like the current speed. I just want them to travel farther and create a bigger "blast."

However, instead, what I actually see in xcode is that the explosion remains exactly the same size, but the interval between drawing gets longer. I see that if I adjust the particle lifetime down to, say, 0.5, xcode repeatedly draws the explosion. If I adjust the interval up to, say, 20, xcode draws exactly the same sized explosion, once every ~20 seconds. That wasn't what I was expecting, at all.

I created an emitter via xcode with:

  • Texture: spark.png

  • Particle birthrate: 5500

  • Maximum Particles: 2266

  • Angle start: 0

  • Angle Range: 360

  • Speed: 70

  • Acceleration: 0

  • Color ramp from white to yellow

And tried the following experiment:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

SKEmitterNode *node = [SKEmitterNode nodeWithFileNamed:@"ExplosionNuke"];
SKEmitterNode *node2 = [SKEmitterNode nodeWithFileNamed:@"ExplosionNuke"];
SKEmitterNode *node3 = [SKEmitterNode nodeWithFileNamed:@"ExplosionNuke"];
SKEmitterNode *node4 = [SKEmitterNode nodeWithFileNamed:@"ExplosionNuke"];

for (UITouch *touch in touches)
CGPoint touchPoint = [touch locationInNode:layerWorld];
CGPoint left = CGPointMake(touchPoint.x - 100, touchPoint.y);
CGPoint right = CGPointMake(touchPoint.x + 100, touchPoint.y);
CGPoint top = CGPointMake(touchPoint.x, touchPoint.y + 100);
CGPoint bottom = CGPointMake(touchPoint.x, touchPoint.y - 100);

node.particleLifetime = .10;
node2.particleLifetime = .99;
node3.particleLifetime = 1.5;
node4.particleLifetime = 300;

node.position = left;
node2.position = right;
node3.position = top;
node4.position = bottom;

[layerWorld addChild:node4];
[layerWorld addChild:node3];
[layerWorld addChild:node2];
[layerWorld addChild:node];


With four nodes bursting on the screen at the same time, the results are:

For lifetime <= 0.99: the shape of the entire explosion does indeed change. smaller values travel shorter distances and result in smaller explosions that disappear faster from view.

for lifetime >= 1.0: the size of the explosion is capped; any value from 1 to 2,250 creates exactly the same size of explosion that remains visible for exactly the same amount of time. A particle with a lifetime of 2,000 does not remain visible any longer than a particle with a lifetime of 1.0. Also, for any lifetime > 1.00, the particle does not fully complete the color ramp. This emitter ramps from white to yellow. All durations < 1.0 complete the ramp to yellow. All values > 1.0 are noticeably "whiter" (even though they fade from the screen at the same time)

I'm now thoroughly confused as to what
is supposed to be doing. Only values from 0.0 to 1.0 have make a visible change. the fact that the color ramp isn't completing for durations > 1.0 makes me think the particles know they're supposed to last longer and have more time to change colors. But, they fade from view before that completes.

What am I doing wrong here? why don't particles in node4 keep moving visibly across--and eventually off--the screen for five minutes? Why do they fade from view at the exact same time as node3?


If your emitter's particleSpeedScale property is negative, your particles will decrease in size until they are no longer visible before particleLifetime seconds have elapsed.

The particleSpeedScale property affects

the rate at which a particle’s scale factor changes per second.

where a positive value increases the size of the particles over time and a negative value decreases the size of the particles.

For example, if the initial particle size is 1 and

particleSpeedScale = 0.5

the particle's size will be 1.5 after 1 second, 2.25 after 2 seconds, etc.

If the initial particle size is 1 and

particleSpeedScale = -0.5

the particle's size will be 0.5 after 1 second, 0.25 after 2 seconds, etc.

I suggest you start by setting particleSpeedScale = 0. This will cause the size of the particles to remain constant throughout the life cycle. Adjust the property as needed.