I have a CAEmitterCell that I am using to emit a continuous background for my game. When the player "dies", I want the background to slow to a stop, so I did this:
- (void)stopAllEmitters:(NSTimeInterval)duration
{
for(CAEmitterLayer* layer in self.emitters)
{
CAEmitterCell* e = layer.emitterCells[0];
CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"emitterCells.emitter.velocity"];
anim.fromValue = @(e.velocity);
anim.toValue = @(0.0);
anim.duration = duration;
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;
[layer addAnimation:anim forKey:@"emitterAnim"];
}
}
Note that all emitterCells are named @"emitter"
, and each layer only has one emitterCell.
This does work for all future-spawned emitter objects, but not for the ones that have already been spawned when I call this.
Is there any way to apply the velocity animation to emitter objects that are already on-screen?