CAEmitterLayer emits multiple CAEmitterCells with specified trajectories. When the trajectory CAEmitterCells fly to the end of time, it will become a particle graph displayed by CAEmitterCells, and then the particle graph will be scattered 360 °. However, only one trajectory particle can be animated completely, but more than two particles will appear. The trajectory particle graph will turn white
Adding a boomEmitterCell will cause the contents of CAEmitterCell in getDogLeftDownEmitterWithImageName and getRedLeftEmitterWithImageName to not display the picture and white blocks
CAEmitterLayer *emitterLayer = [[CAEmitterLayer alloc] init];
emitterLayer.emitterPosition = CGPointMake(self.view.layer.bounds.size.width -100, self.view.layer.bounds.size.height - 100);
emitterLayer.emitterSize = CGSizeMake(50, 100.f);
emitterLayer.emitterShape = kCAEmitterLayerLine;
emitterLayer.emitterMode = kCAEmitterLayerOutline;
emitterLayer.renderMode = kCAEmitterLayerOldestLast;
CAEmitterCell *dogleftEmitterCell = [self getRedLeftEmitterWithImageName:[imageArray objectAtIndex:0]];
CAEmitterCell *redLeftEmitterCell = [self getRedLeftEmitterWithImageName:[imageArray objectAtIndex:0]];
emitterLayer.emitterCells = @[dogleftEmitterCell,redLeftEmitterCell];
[self.view.layer addSublayer:emitterLayer];
//狗头左下
- (CAEmitterCell *)getDogLeftDownEmitterWithImageName:(NSString *)imageName {
CAEmitterCell *emitterCell = [[CAEmitterCell alloc] init];
emitterCell.name = @"左下狗头";
emitterCell.contents = (__bridge id _Nullable)[UIImage imageNamed:@"emoji_6"].CGImage;
//产生频率
emitterCell.birthRate = 1;
//存活时长
emitterCell.lifetime = 0.6;
//速度
emitterCell.velocity = 100;
emitterCell.xAcceleration = -1000.f; // 模拟重力影响
emitterCell.scale = 0.2;
emitterCell.scaleSpeed = 0.25;
emitterCell.emissionLongitude = M_PI_2;
// emitterCell.emissionRange = M_PI_4;
emitterCell.emitterCells = @[[self boomEmitterCell]];
return emitterCell;
}
//红包左上
- (CAEmitterCell *)getRedLeftEmitterWithImageName:(NSString *)imageName {
CAEmitterCell *emitterCell = [[CAEmitterCell alloc] init];
emitterCell.name = @"红包";
emitterCell.contents = (__bridge id _Nullable)[UIImage imageNamed:@"emoji_7"].CGImage;
//产生频率
emitterCell.birthRate = 10;
//存活时长
emitterCell.lifetime = 0.6;
// emitterCell.beginTime = self.beginTime;
//速度
emitterCell.velocity = 100;
emitterCell.yAcceleration = -1000.f; // 模拟重力影响
emitterCell.scale = 0.2;
// emitterCell.scaleRange = 0.06;
emitterCell.scaleSpeed = 0.25;
emitterCell.emissionLongitude = M_PI;
// CAEmitterCell *emitterCell = [self boomEmitterCell];
emitterCell.emitterCells = @[[self boomEmitterCell]];
return emitterCell;
}
- (CAEmitterCell *)boomEmitterCell {
// 爆炸
CAEmitterCell * explodeCell = [CAEmitterCell emitterCell];
explodeCell.name = @"explodeCell";
explodeCell.birthRate = 2.f;
explodeCell.lifetime = 0.6f;
// explodeCell.velocity = 0.f;
// explodeCell.scale = 1.0;
// explodeCell.redSpeed = -1.5; //爆炸的时候变化颜色
// explodeCell.blueRange = 1.5; //爆炸的时候变化颜色
// explodeCell.greenRange = 1.f; //爆炸的时候变化颜色
// explodeCell.birthRate = 1.0;
// explodeCell.velocity = 0;
// explodeCell.scale = 2.5;
// explodeCell.redSpeed =-1.5;
// explodeCell.blueSpeed =+1.5;
// explodeCell.greenSpeed =+1.0;
// explodeCell.lifetime = 0.35;
explodeCell.contents = (__bridge id _Nullable)[[UIImage imageNamed:@"allStart"] CGImage];
// 火花
// CAEmitterCell * sparkCell = [CAEmitterCell emitterCell];
// sparkCell.name = @"sparkCell";
//
// sparkCell.birthRate = 3.f;
// sparkCell.lifetime = 3.f;
// sparkCell.velocity = 125.f;
//// sparkCell.yAcceleration = 75.f; // 模拟重力影响
// sparkCell.emissionRange = M_PI * 2; // 360度
//
// sparkCell.scale = 1.2f;
// sparkCell.contents = (id)[[UIImage imageNamed:@"star_white_stroke"] CGImage];
// sparkCell.redSpeed = 0.4;
// sparkCell.greenSpeed = -0.1;
// sparkCell.blueSpeed = -0.1;
// sparkCell.alphaSpeed = -0.25;
// explodeCell.emitterCells = @[sparkCell];
return explodeCell;
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Due to the release of ProMotion devices, the system may switch frame rates in certain scenarios, resulting in the loss of reference value for data collected through CADisplayLink callbacks at a fixed 60Hz frame rate. We cannot distinguish whether the slow callback of CADisplayLink is due to a stutter or a system switch in frame rate.
I know Hitch Time Ratio, but I can't use this scheme for some reasons.
How can I distinguish between stuck and frame rate gear shift in CADisplaylink callback?
In iOS 15, CADisplayLink.preferredFrameRateRange.preferred always returns 0, while minimum and maximum do change. Can I use these minimum and maximum range values as criteria to distinguish between frame rate switching and stuttering?