ioscaemitterlayercaemittercell

Trouble getting CAEmitterLayer to show particles


I have read a few tutorials and looked over the documentation but I cannot get my CAEmitterLayer to show any particles. I have a CAEmitterLayer and CAEmitterCell property and both have the attributes nonatomic, and storng. Perhaps I am missing a step but I have imported QuartzCore and here is my methods to setup the layer and cell which I call in viewDidLoad:

-(void) setupEmitter{

 self.emitterLayer = [CAEmitterLayer layer];
 self.emitterLayer.bounds = CGRectMake(0, 0, 200,200);
 self.emitterLayer.position = CGPointMake(100,100);
 self.emitterLayer.backgroundColor = [[UIColor clearColor] CGColor];
 self.emitterLayer.emitterPosition = CGPointMake(100, 100);
 self.emitterLayer.emitterSize = CGSizeMake(100, 100);
 [self.view.layer addSublayer:self.emitterLayer];
}


-(void) setupEmitterCell {

 self.emitterCell = [CAEmitterCell emitterCell];
 self.emitterCell.name = @"goldstar";
 self.emitterCell.contents = (id)[UIImage imageNamed:@"bokeh.png"].CGImage;
 self.emitterCell.birthRate = 66;
 self.emitterCell.lifetime = 0.5;;
 self.emitterCell.lifetimeRange = 0.6;
 self.emitterCell.velocity = 300;
 self.emitterCell.emissionRange = 2 * M_PI;
 self.emitterCell.spin = 0.0;
 self.emitterCell.spinRange = 4 * M_PI;
 self.emitterCell.color = [[UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0] CGColor];
 self.emitterCell.scale = 1.0;
 self.emitterCell.scaleRange = 1.0;
 self.emitterCell.emitterCells = [NSArray arrayWithObjects:self.emitterCell, nil];
}

Solution

  • I could be wrong, but the problem seems to be that you forgot to tell the emitter what it should use as cells? Maybe using [self.emitterLayer setEmitterCells:self.emitterCell]; might help.