Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fading out emitter cells with Core Animation

I am creating a particle animation with CAEmitterLayer and CAEmitterCell instances. There is no problem with the animation but I want them to fade out slowly. I am using the code below but the particles disappear suddenly, no fade out animation there.

        NSString *animationPath = [NSString stringWithFormat:@"emitterCells.%@.birthRate", cell.name];
        CABasicAnimation *birthRateAnimation = [CABasicAnimation animationWithKeyPath:animationPath];
        birthRateAnimation.fromValue = [NSNumber numberWithFloat:30.0];
        birthRateAnimation.toValue = [NSNumber numberWithFloat:0.0];
        birthRateAnimation.removedOnCompletion = NO;
        birthRateAnimation.duration = 10.0;
        [emitterLayer addAnimation:birthRateAnimation forKey:@"birthRate"];

This code runs in a for loop for five different emitter cells.

Do you spot an error in this code?

Thanks

like image 726
Élodie Petit Avatar asked Jun 16 '14 13:06

Élodie Petit


1 Answers

For the CAEmitterCell's set the alpha speed value to -1.0/lifetime.

like image 69
Andrei Ardelean Avatar answered Oct 10 '22 00:10

Andrei Ardelean