#import "FireworksVIEw.h" @implementation FireworksVIEw - (voID)launchFirework{ //Load the spark image for the particle CAEmitterLayer *mortor = [CAEmitterLayer layer]; mortor.emitterposition = CGPointMake(self.bounds.size.wIDth/2,self.bounds.size.height*(.75)); mortor.renderMode = kCAEmitterLayerAdditive; //Invisible particle representing the rocket before the explosion CAEmitterCell *rocket = [CAEmitterCell emitterCell]; rocket.emissionLongitude = -M_PI / 2; rocket.emissionLatitude = 0; rocket.lifetime = 1.6; rocket.birthRate = 1; rocket.veLocity = 400; rocket.veLocityRange = 100; rocket.yacceleration = 250; rocket.emissionRange = M_PI / 4; rocket.color = CGcolorCreatecopy([UIcolor colorWithRed:.5 green:.5 blue:.5 Alpha:.5].CGcolor); rocket.redRange = 0.5; rocket.greenRange = 0.5; rocket.blueRange = 0.5; //name the cell so that it can be animated later using keypath [rocket setname:@"rocket"]; //Flare particles emitted from the rocket as it flys CAEmitterCell *flare = [CAEmitterCell emitterCell]; flare.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage; flare.emissionLongitude = (4 * M_PI) / 2; flare.scale = 0.4; flare.veLocity = 100; flare.birthRate = 45; flare.lifetime = 1.5; flare.yacceleration = 350; flare.emissionRange = M_PI / 7; flare.AlphaSpeed = -0.7; flare.scaleSpeed = -0.1; flare.scaleRange = 0.1; flare.beginTime = 0.01; flare.duration = 0.7; //The particles that make up the explosion CAEmitterCell *firework = [CAEmitterCell emitterCell]; firework.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage; firework.birthRate = 9999; firework.scale = 0.6; firework.veLocity = 130; firework.lifetime = 2; firework.AlphaSpeed = -0.2; firework.yacceleration = 80; firework.beginTime = 1.5; firework.duration = 0.1; firework.emissionRange = 2 * M_PI; firework.scaleSpeed = -0.1; firework.spin = 2; //name the cell so that it can be animated later using keypath [firework setname:@"firework"]; //preSpark is an invisible particle used to later emit the spark CAEmitterCell *preSpark = [CAEmitterCell emitterCell]; preSpark.birthRate = 80; preSpark.veLocity = firework.veLocity * 0.70; preSpark.lifetime = 1.7; preSpark.yacceleration = firework.yacceleration * 0.85; preSpark.beginTime = firework.beginTime - 0.2; preSpark.emissionRange = firework.emissionRange; preSpark.greenSpeed = 100; preSpark.blueSpeed = 100; preSpark.redSpeed = 100; //name the cell so that it can be animated later using keypath [preSpark setname:@"preSpark"]; //The 'sparkle' at the end of a firework CAEmitterCell *spark = [CAEmitterCell emitterCell]; spark.contents = (ID)[UIImage imagenamed:@"tspark.png"].CGImage; spark.lifetime = 0.05; spark.yacceleration = 250; spark.beginTime = 0.8; spark.scale = 0.4; spark.birthRate = 10; preSpark.emitterCells = [NSArray arrayWithObjects:spark,nil]; rocket.emitterCells = [NSArray arrayWithObjects:flare,firework,preSpark,nil]; mortor.emitterCells = [NSArray arrayWithObjects:rocket,nil]; [self.layer addSublayer:mortor]; }解决方法 答案是,使用CAEmitter,没有WAY – 委托等 – 在结束循环时停止发射器.当你认为应该删除它时,你唯一能做的就是优雅地将它从图层中移除. 总结
以上是内存溢出为你收集整理的ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它全部内容,希望文章能够帮你解决ios – 当它结束CAEmitterLayer的CAEmitter单元格的生命周期时如何删除CAEmitterLayer – 而不是重复直到从超级图层中删除它所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)