Reputation: 4336
I am trying to have a CAEmitterLayer make a kind of lightsaber animation. I want a beam of light to appear from a point and stop. My problem is that I cannot get the beginning of the animation to happen smoothly. As soon as I run the code it just appears as if a couple of seconds have already passed without any animation.
I stripped down the code as much as possible to see if I could find the source of the problem, but even at its simplest it still happens. Here is a sample of the code I have right now which still has the problem:
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.emitterPosition = CGPointMake(10, 10);
CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];
emitterCell.contents = (id)[[UIImage imageNamed:@"LightParticle"] CGImage];
emitterCell.birthRate = 100;
emitterCell.lifetime = 10;
emitterCell.velocity = 10;
emitterLayer.emitterCells = @[emitterCell];
[self.view.layer addSublayer:emitterLayer];
I'm guessing that I must have missed something obvious but I haven't been able to fix this for days.
Setting the birthRate to 0 will cause the beam to disappear smoothly, but setting it back to any number will cause it to appear with no animation again.
Thank you for your help.
Upvotes: 2
Views: 1485
Reputation: 4336
Finally found the answer to this here: iOS 7 CAEmitterLayer spawning particles inappropriately
This is what I was missing:
emitter.beginTime = CACurrentMediaTime();
Upvotes: 18
Reputation: 81
emitterCell.birthRate = 0.1;
emitterCell.lifetime = 10;
emitterCell.velocity = 10;
birthRate could be very small but not 0.
Then change the scale speed
emitterCell.scale=0.01; emitterCell.scaleSpeed=0.1;
hope this can give you some ideas.
Upvotes: 0