10

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

Élodie Petit
  • 5,774
  • 6
  • 50
  • 88

1 Answers1

23

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

Andrei Ardelean
  • 474
  • 4
  • 12