Create a circle of particles using CAEmitterLayer

1.2k Views Asked by At

I'm trying to use the UIKit CAEmitterLayer to give feedback to the user when he touches the screen. What I'd like to do is a circle of particles, that grows overtime.

I was thinking that if I setup the particles with the same speed (no velocity range), the particles would all move from the center point at the same speed, and therefore, draw a circle.

However, it looks like the speed is still random, in a range between 0 and the speed I've chosen as velocity.

Is there a way to force the speed to be an exact value ?

    dragEmitter.emitterPosition = CGPointMake(50, 50);
dragEmitter.emitterSize = CGSizeMake(1, 1);

CAEmitterCell* fire = [CAEmitterCell emitterCell];
fire.birthRate = 10;
fire.lifetime = 0.7;
fire.lifetimeRange = 0;
fire.color = [[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] CGColor];
fire.contents = (id)[[UIImage imageNamed:@"Particles_fire.png"] CGImage];
[fire setName:@"fire"];

fire.velocity = 50;
fire.velocityRange = 0;
fire.emissionRange = 2*M_PI;
fire.emissionLatitude = 0;
fire.emissionLongitude = 0;

Thanks for you help !

1

There are 1 best solutions below

1
On

Frankly, it's hard to imagine 100% the same picture of the particle system you want but i think it gets close to that what needed a few months ago. Please try the following set-up for the emitter cell or try experimenting with the values based on the set-up below:

    .
    .
    emitter.emitterPosition = CGPointMake(...);
    emitter.renderMode = kCAEmitterLayerBackToFront;

    CAEmitterCell* star = [CAEmitterCell emitterCell]
    star.emissionLongitude = M_PI*2;
    star.emissionRange = M_PI*2;
    star.lifetime = 2.5;
    star.birthRate = 20;
    star.velocity = 120;
    star.velocityRange = 20;
    star.color = [UIColor colorWithRed:49.0/255.0 green:168.0/255.0 blue:181.0/255.0 alpha:0.6].CGColor;
    star.contents = (id)image.CGImage;
    star.redRange = 0.1;
    star.greenRange = 0.1;
    star.blueRange = 0.1;
    .
    .