Emitter Cell Attenuation with Core Animation

I am creating particle animations with instances of CAEmitterLayer and CAEmitterCell. There is no problem with the animation, but I want them to slowly disappear. I use the following code, but the particles suddenly disappear, and the animation does not disappear 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.

Did you notice an error in this code?

thanks

+7
ios core-animation caemitterlayer caemittercell
source share
1 answer

For CAEmitterCell, set the alpha speed to -1.0 / lifetime.

+14
source share

All Articles