0
我讀了一些教程,並期待該文檔了,但我不能讓我的CAEmitterLayer表現出任何顆粒。我有一個CAEmitterLayer和CAEmitterCell屬性,它們都具有nonatomic屬性和storng屬性。也許我錯過了一步,但我已經進口QuartzCore,這裏是我的方法來設置層和單元,我在viewDidLoad中稱:麻煩CAEmitterLayer顯示顆粒
-(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];
}
這就是'setupEmitterCell:'最後一行正在做的事情。 –
並非如此。您正在給發射器單元發射器單元。但是,正如@Boby_Wan所說,你並沒有給予任何單元。 – matt
我看到它的方式,在'setupEmitter'處創建一個發射器;在'setupEmitterCell'你創建發射器應該使用的單元;在'setupEmitterCell'結尾處添加單元格到您的單元格? (我不確定這最後一部分。)但是你永遠不會告訴'self.emitterLayer'使用'self.emitterCell'作爲它的單元格。 – RoberRM