0

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

1 Answers1

2

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.

RoberRM
  • 883
  • 9
  • 18
  • That is what the last line of `setupEmitterCell:` is doing. – Alexander Bollbach Sep 07 '15 at 02:45
  • 1
    Not so. You're giving the emitter cell emitter cells. But, as @Boby_Wan says, you are not giving the _emitter_ any cells. – matt Sep 07 '15 at 03:03
  • The way I see it, at `setupEmitter` you create an emitter; at `setupEmitterCell` you create the cells that the emitter should use; at the end of `setupEmitterCell` you add cells to your cells? (I'm not sure about this last part.) But you never tell `self.emitterLayer` to use `self.emitterCell` as its cells. – RoberRM Sep 07 '15 at 16:04
  • Ok I caught that. It was a bit confusing with both the Layer and Cell having "cells" properties and I simply glossed over that. Thanks! – Alexander Bollbach Sep 07 '15 at 20:36
  • You are welcome! I'm happy I was able to help you. :) – RoberRM Sep 08 '15 at 00:36