使用CAEmitterLayer创建一个粒子圆 [英] Create a circle of particles using CAEmitterLayer
问题描述
我正在尝试使用UIKit CAEmitterLayer向用户触摸屏幕时提供反馈. 我想做的是一圈粒子,随着时间的推移会越来越大.
I'm trying to use the UIKit CAEmitterLayer to give feedback to the user when he touches the screen. What I'd like to do is a circle of particles, that grows overtime.
我当时想,如果以相同的速度(没有速度范围)设置粒子,则粒子将以相同的速度从中心点移动,因此绘制一个圆.
I was thinking that if I setup the particles with the same speed (no velocity range), the particles would all move from the center point at the same speed, and therefore, draw a circle.
但是,看起来速度仍然是随机的,介于0和我选择的速度之间.
However, it looks like the speed is still random, in a range between 0 and the speed I've chosen as velocity.
是否有一种方法可以强制将速度设为精确值?
Is there a way to force the speed to be an exact value ?
dragEmitter.emitterPosition = CGPointMake(50, 50);
dragEmitter.emitterSize = CGSizeMake(1, 1);
CAEmitterCell* fire = [CAEmitterCell emitterCell];
fire.birthRate = 10;
fire.lifetime = 0.7;
fire.lifetimeRange = 0;
fire.color = [[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] CGColor];
fire.contents = (id)[[UIImage imageNamed:@"Particles_fire.png"] CGImage];
[fire setName:@"fire"];
fire.velocity = 50;
fire.velocityRange = 0;
fire.emissionRange = 2*M_PI;
fire.emissionLatitude = 0;
fire.emissionLongitude = 0;
感谢您的帮助!
推荐答案
坦率地说,很难想象100%的粒子系统具有相同的图像,但是我认为它已经接近几个月前的水平.请为发射器电池尝试以下设置,或尝试根据以下设置尝试使用值:
Frankly, it's hard to imagine 100% the same picture of the particle system you want but i think it gets close to that what needed a few months ago. Please try the following set-up for the emitter cell or try experimenting with the values based on the set-up below:
.
.
emitter.emitterPosition = CGPointMake(...);
emitter.renderMode = kCAEmitterLayerBackToFront;
CAEmitterCell* star = [CAEmitterCell emitterCell]
star.emissionLongitude = M_PI*2;
star.emissionRange = M_PI*2;
star.lifetime = 2.5;
star.birthRate = 20;
star.velocity = 120;
star.velocityRange = 20;
star.color = [UIColor colorWithRed:49.0/255.0 green:168.0/255.0 blue:181.0/255.0 alpha:0.6].CGColor;
star.contents = (id)image.CGImage;
star.redRange = 0.1;
star.greenRange = 0.1;
star.blueRange = 0.1;
.
.
这篇关于使用CAEmitterLayer创建一个粒子圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!