CAEmitterLayer是一个例子引擎,我们可以把它比作一个太阳,它向四面八方辐射粒子,然后我们用上图片和它的一些设置就做出来了爆炸效果,详细的设置见代码和注释:
CAEmitterLayer *emitter = [CAEmitterLayer layer]; emitter.frame = self.view.bounds; [self.view.layer addSublayer:emitter]; //configure emitter kCAEmitterLayerAdditive合并重叠部位的亮度,使之更亮 emitter.renderMode = kCAEmitterLayerAdditive; emitter.emitterPosition = CGPointMake(emitter.frame.size.width / 2.0, emitter.frame.size.height / 2.0); //create a particle template CAEmitterCell *cell = [[CAEmitterCell alloc] init]; cell.contents = (__bridge id)[UIImage imageNamed:@"fire.png"].CGImage; //加速或者扩大整个粒子系统 cell.birthRate = 150; //存在时间 cell.lifetime = 5.0; //混合图片内容颜色的混合色(重叠部分颜色) cell.color = [UIColor colorWithRed:0.98f green:0.54f blue:0.14f alpha:1.00f].CGColor; //每秒钟透明度变化,逐渐消失 cell.alphaSpeed = -0.4; //控制粒子辐射的速度 cell.velocity = 100; //粒子辐射速度的范围,像是一个最大速度 cell.velocityRange = 100; //辐射角度,如果小于360度就是一个扇形区域 cell.emissionRange = M_PI * 2.0; //add particle template to emitter emitter.emitterCells = @[cell];
github下载地址:https://github.com/codeliu6572/CAEmitterLayer-