使用CAEmitterLayer在圆圈或CGPath周围绘制粒子 [英] use CAEmitterLayer to draw particles around a circle or a CGPath

查看:142
本文介绍了使用CAEmitterLayer在圆圈或CGPath周围绘制粒子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iOS 5的粒子系统(CAEmitterLayer和CAEmitterCell)来围绕一个圆圈绘制粒子(甚至更好,一个CGPath),但我不知道该怎么做。我能做的最好的是制作一个弧(通过修改CAEmitterCell的yAcceleration属性),但我不能做一个完整的循环。当然,我可以做多个圆弧来模拟圆形,但结非常明显。此外,我不想使用蒙版,因为看起来边缘的粒子被裁剪。任何想法如何做到这一点?

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?

推荐答案

您可以使用CAKeyframeAnimation为emitterPosition设置动画:

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"]; 

这篇关于使用CAEmitterLayer在圆圈或CGPath周围绘制粒子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆