我已阅读了一些教程并查看了文档,但我无法让我的CAEmitterLayer显示任何粒子。我有一个CAEmitterLayer和CAEmitterCell属性,它们都具有nonatomic和storng属性。也许我错过了一步,但我已经导入了QuartzCore,这是我设置我在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];
}
答案 0 :(得分:2)
我可能是错的,但问题似乎是你忘了告诉发射器应该用什么作为细胞?也许使用[self.emitterLayer setEmitterCells:self.emitterCell];
可能会有所帮助。