问题
I'm trying to use iOS 5's particle system (CAEmitterLayer and CAEmitterCell) to draw particles around a circle (or even better, a CGPath), but I don't know how to do it. The best I could do is make an arc (by modifying the yAcceleration property of CAEmitterCell), but I can't do a complete circle. Of course, I could do multiple arcs to simulate a circle, but the "knots" are very visible. Also, I don't want to use masks, because it would seem like the particles at the edges are cropped. Any ideas how to do that?
回答1:
You can use a CAKeyframeAnimation to animate the emitterPosition:
CAKeyframeAnimation *particleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
[particleAnimation setPath:yourPath];
[particleAnimation setDuration:1.0];
[particleAnimation setCalculationMode:kCAAnimationPaced];
[yourEmitterLayer addAnimation:particleAnimation forKey:@"yourAnimation"];
回答2:
You want to use particleEmitter.emitterShape = kCAEmitterLayerCircle
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAEmitterLayer_class/Reference/Reference.html
回答3:
yourEmitter.emitterShape = kCAEmitterLayerCircle;
yourEmitter.emitterMode = kCAEmitterLayerOutline;
来源:https://stackoverflow.com/questions/8296775/use-caemitterlayer-to-draw-particles-around-a-circle-or-a-cgpath