iOS之CAEmitterLayer详解
CAEmitterLayer(粒子系统)学习笔记(含Demo)
iOS[QuartzCore框架](CAEmitterLayer精解)(4)
交作业
贴代码
- (instancetype)initWithFrame:(CGRect)frame{
if ([super initWithFrame:frame]) {
size = frame.size;
cirframe = frame;
[self createCA];
}return self;
}
- (void)createCA{
//masklayer
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
CAShapeLayer *cirLayer = [CAShapeLayer layer];
cirLayer.path = path.CGPath;
cirLayer.fillColor = [UIColor redColor].CGColor;
//渐变layer
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, size.width, size.height);
gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:29/255.0f green:204/255.0f blue:140/255.0f alpha:1].CGColor,
(__bridge id)[UIColor colorWithRed:171/255.0f green:243/255.0f blue:131/255.0f alpha:1].CGColor
];
gradientLayer.startPoint = CGPointMake(0.5f,1);
gradientLayer.endPoint = CGPointMake(0.5f, 0);
[self.layer addSublayer:gradientLayer];
self.layer.mask = cirLayer;
//emitterLayer
UIImage *emitterCellname = [UIImage imageNamed:@"圆"];
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
//设置粒子源(粒子发射范围)的形状
emitterLayer.emitterShape = kCAEmitterLayerPoint;
//粒子发射模式
emitterLayer.renderMode = kCAEmitterLayerVolume;
emitterLayer.emitterSize = size;
emitterLayer.emitterPosition = CGPointMake(size.width/2, size.height);
CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];
emitterCell.name = @"圆";
emitterCell.enabled = YES;
emitterCell.contents = (__bridge id)emitterCellname.CGImage;
//粒子出生速度和存在时间
emitterCell.birthRate = 2;
emitterCell.lifetime = 8.f;
//粒子向屏幕右方(+)向偏移及偏移范围大小
emitterCell.velocity = 10;
emitterCell.velocityRange = -10;
//粒子沿y轴方向发射加速度分量
emitterCell.yAcceleration = -40;
//粒子在发射点可以发射的角度
emitterCell.emissionRange = -M_PI;
//粒子大小/范围/变化速率
emitterCell.scale = 0.1;
emitterCell.scaleRange = 0.1;
emitterCell.scaleSpeed = 0.2;
//粒子过滤器放大模式
emitterCell.magnificationFilter = kCAFilterNearest;
emitterCell.minificationFilter = kCAFilterTrilinear;
emitterLayer.emitterCells = @[emitterCell];
[self.layer addSublayer:emitterLayer];
}
CAEmitterLayer
birthRate:粒子产生系数,默认1.0;
emitterCells: 装着CAEmitterCell对象的数组,被用于把粒子投放到layer上;
emitterDepth:决定粒子形状的深度联系:emitter shape
emitterZposition:发射源的z坐标位置;
lifetime:粒子生命周期
preservesDepth:不是多很清楚(粒子是平展在层上)
scale:粒子的缩放比例:
seed:用于初始化随机数产生的种子
spin:自旋转速度
velocity:粒子速度
CAEmitterCell
CAEmitterCell类代从CAEmitterLayer射出的粒子;emitter cell定义了粒子发射的方向。
alphaRange: 一个粒子的颜色alpha能改变的范围;
alphaSpeed:粒子透明度在生命周期内的改变速度;
birthrate:粒子参数的速度乘数因子;每秒发射的粒子数量
blueRange:一个粒子的颜色blue 能改变的范围;
blueSpeed: 粒子blue在生命周期内的改变速度;
color:粒子的颜色
contents:是个CGImageRef的对象,既粒子要展现的图片;
contentsRect:应该画在contents里的子rectangle:
emissionLatitude:发射的z轴方向的角度
emissionLongitude:x-y平面的发射方向
emissionRange;周围发射角度
emitterCells:粒子发射的粒子
enabled:粒子是否被渲染
greenrange: 一个粒子的颜色green 能改变的范围;
greenSpeed: 粒子green在生命周期内的改变速度;
lifetime:生命周期
lifetimeRange:生命周期范围 lifetime= lifetime(+/-) lifetimeRange
magnificationFilter:不是很清楚好像增加自己的大小
minificatonFilter:减小自己的大小
minificationFilterBias:减小大小的因子
name:粒子的名字
redRange:一个粒子的颜色red 能改变的范围;
redSpeed; 粒子red在生命周期内的改变速度;
scale:缩放比例:
scaleRange:缩放比例范围;
scaleSpeed:缩放比例速度:
spin:粒子旋转角度
spinrange:粒子旋转角度范围
velocity:速度
velocityRange:速度范围
xAcceleration:粒子x方向的加速度分量
yAcceleration:粒子y方向的加速度分量
zAcceleration:粒子z方向的加速度分量