iOS 粒子效果

參考文章 http://www.itdecent.cn/p/df878cef6795

static NSString *kX = @"curveX";
static NSString *kY = @"curveY";

//粒子效果
 -(void)effectOfParticle{

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width / 2 - 50, self.bounds.size.height / 2.0, 50, 50)];
     // view.backgroundColor = [UIColor yellowColor];
view.layer.cornerRadius = 50;
[self addSubview:view];

//create particle emmitter layer
//CAEmitterLayer負(fù)責(zé)發(fā)射粒子(粒子也可以發(fā)射粒子)
CAEmitterLayer *emitter = [CAEmitterLayer layer];
emitter.frame = view.bounds;
//決定粒子發(fā)射形狀的中心點
emitter.emitterPosition = CGPointMake(100, 100);
emitter.emitterZPosition = 3.0;
emitter.emitterShape = kCAEmitterLayerCircle;//發(fā)射器形狀
emitter.emitterMode = kCAEmitterLayerVolume;//3d圓形的體積內(nèi)發(fā)射

emitter.preservesDepth = YES; //是否開啟三維空間模式
emitter.emitterDepth = 2.0;//發(fā)射器的深度,有時可能會產(chǎn)生立體效果
emitter.spin = 50;//粒子的旋轉(zhuǎn)角度
[view.layer addSublayer:emitter];

//configure emitter
emitter.renderMode = kCAEmitterLayerAdditive;//渲染模式
//emitter.emitterPosition = CGPointMake(emitter.frame.size.width /2.0, emitter.frame.size.height / 2.0);

//creat a particle template]
CAEmitterCell *cell = [[CAEmitterCell alloc] init];
cell.contents = (__bridge id _Nullable)([UIImage imageNamed:@"2.png"].CGImage);
cell.birthRate = 15.0;
cell.lifetime = 5.0;
cell.enabled = YES;//是否打開粒子的渲染效果
//  cell.color = [UIColor colorWithRed:1 green:0.5 blue:0.1 alpha:1.0].CGColor;
cell.alphaSpeed = -0.4;

cell.velocity = 50; //粒子的速度
cell.velocityRange = 70;//粒子的速度范圍
cell.emissionRange = M_PI * 2.0;
//creat a particle template]
CAEmitterCell *cell2 = [[CAEmitterCell alloc] init];
cell2.contents = (__bridge id _Nullable)([UIImage imageNamed:@"2.png"].CGImage);
cell2.birthRate = 15.0;
cell2.lifetime = 5.0;
cell2.color = [UIColor colorWithRed:1 green:0.5 blue:0.1 alpha:1.0].CGColor;
cell2.alphaSpeed = -0.4;
cell2.velocity = 50;
cell2.velocityRange = 50;
cell2.emissionRange = M_PI * 2.0;
//add pareticle template to emitter
emitter.emitterCells = @[cell,cell2];

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容