我的目标是制作一个类似爆炸的动画,其中在短时间内发射出许多粒子。我的问题是 CAEmitterLayer 在开始发射时会添加“未来”粒子,使其看起来像动画已经运行了一段时间。
如何禁用或解决此问题?当我增加birthRate 时,我只希望粒子从emitterPosition 开始出现,而不是在CAEmitterCell 的预计生命周期中的所有点。任何帮助表示赞赏。
#import "EmitterView.h"
@interface EmitterView ()
@property CAEmitterLayer* emitter;
@end
@implementation EmitterView
- (void) awakeFromNib {
[super awakeFromNib];
self.emitter = (CAEmitterLayer*)self.layer;
CAEmitterCell* snowflake = [CAEmitterCell emitterCell];
snowflake.contents = (id)[[UIImage imageNamed: @"snowflake"] CGImage];
snowflake.lifetime = 3;
snowflake.birthRate = 1;
snowflake.velocity = 50;
snowflake.emissionRange = 3.1415;
self.emitter.birthRate = 0;
self.emitter.emitterCells = [NSArray arrayWithObject: snowflake];
self.emitter.emitterPosition = CGPointMake(100, 100);
self.emitter.emitterSize = CGSizeMake(0, 0);
self.emitter.emitterShape = kCAEmitterLayerPoint;
}
+ (Class) layerClass {
return [CAEmitterLayer class];
}
- (void) burst {
self.emitter.birthRate = 10;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
self.emitter.birthRate = 0;
});
}
@end