5

我在玩 CAEmitterCell,但大多数效果都是非常快的效果,比如烟花。但我想要像你在www.findyourwaytooz.com上看到的那样缓慢的“星星”效果

我怎么能用 CAEmitterCell 做到这一点?

谢谢 :)

4

1 回答 1

7

我有一个项目使用以下发射器设置,它非常准确地模仿了我认为你的意思:

//set ref to the layer
starsEmitter = (CAEmitterLayer*)self.layer; //2

//configure the emitter layer
starsEmitter.emitterPosition = CGPointMake(160, 240);
starsEmitter.emitterSize = CGSizeMake(self.superview.bounds.size.width,self.superview.bounds.size.height);
NSLog(@"width = %f, height = %f", starsEmitter.emitterSize.width, starsEmitter.emitterSize.height);
starsEmitter.renderMode = kCAEmitterLayerPoints;
starsEmitter.emitterShape = kCAEmitterLayerRectangle;
starsEmitter.emitterMode = kCAEmitterLayerUnordered;

CAEmitterCell* stars = [CAEmitterCell emitterCell];
stars.birthRate = 0;
stars.lifetime = 10;
stars.lifetimeRange = 0.5;
stars.color = [[UIColor colorWithRed:255 green:255 blue:255 alpha:0] CGColor];
stars.contents = (id)[[UIImage imageNamed:@"particle.png"] CGImage];
stars.velocityRange = 500;
stars.emissionRange = 360;
stars.scale = 0.2;
stars.scaleRange = 0.1;
stars.alphaRange = 0.3;
stars.alphaSpeed  = 0.5;    
[stars setName:@"stars"];

//add the cell to the layer and we're done
starsEmitter.emitterCells = [NSArray arrayWithObject:stars];

我将示例项目上传到 GitHub:SimpleCAEmitterLayer

于 2013-02-12T23:47:47.920 回答