Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAEmitterCell - slow stars or light effect

I'm playing around with CAEmitterCell, but most effects are very fast effects like the firework. But I want to have a slow "stars" effect like you see here on www.findyourwaytooz.com

How can I do that with CAEmitterCell?

Thank you :)

like image 208
cuSoon2013 Avatar asked Feb 12 '13 18:02

cuSoon2013


1 Answers

I have a project that uses the following setup for the emitter, and it pretty accurately mimics what I think you mean:

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

I uploaded the sample project to GitHub: SimpleCAEmitterLayer

like image 185
jhilgert00 Avatar answered Sep 28 '22 07:09

jhilgert00