Skip to content

Instantly share code, notes, and snippets.

@evanlong
Created August 4, 2012 20:54
Show Gist options
  • Save evanlong/3259854 to your computer and use it in GitHub Desktop.
Save evanlong/3259854 to your computer and use it in GitHub Desktop.
ParticleFun
- (void)viewDidLoad {
[super viewDidLoad];
UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 200.0f, 200.0f)];
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
emitterLayer.emitterSize = CGSizeMake(20.0f, 20.0f);
emitterLayer.emitterPosition = CGPointMake(90.0f, 90.0f);
NSMutableArray *cells = [NSMutableArray array];
CAEmitterCell *cell = [CAEmitterCell emitterCell];
cell.contents = (id)[UIImage imageNamed:@"F2.png"].CGImage;
cell.color = [UIColor orangeColor].CGColor;
cell.alphaRange = 50;
cell.alphaSpeed = 5;
cell.birthRate = 50;
cell.velocity = 75;
cell.velocityRange = 3;
cell.lifetime = 1;
cell.lifetimeRange = .75;
cell.scale = 1.0;
cell.scaleRange = 1;
cell.spin = M_PI_2;
cell.spinRange = M_PI * 2;
cell.emissionLongitude = -M_PI_2;
cell.emissionRange = M_PI/8;
[cell setName:@"cell"];
[cells addObject:cell];
cell = [CAEmitterCell emitterCell];
cell.contents = (id)[UIImage imageNamed:@"F2.png"].CGImage;
cell.color = [UIColor orangeColor].CGColor;
cell.alphaRange = 80;
cell.alphaSpeed = 5;
cell.birthRate = 300;
cell.velocity = 50;
cell.velocityRange = 25;
cell.lifetime = 1;
cell.lifetimeRange = .8;
cell.scale = 1.0;
cell.scaleRange = 1 ;
cell.spin = M_PI_2;
cell.spinRange = M_PI * 2;
cell.emissionLongitude = -M_PI_2;
cell.emissionRange = M_PI/4;
[cell setName:@"cell2"];
[cells addObject:cell];
CAEmitterCell *cellCell = [CAEmitterCell emitterCell];
cellCell.contents = (id)[UIImage imageNamed:@"F2.png"].CGImage;
cellCell.color = [UIColor darkGrayColor].CGColor;
cellCell.alphaRange = 80;
cellCell.alphaSpeed = 5;
cellCell.birthRate = 1;
cellCell.velocity = 30;
cellCell.velocityRange = 10;
cellCell.lifetime = 3;
cellCell.lifetimeRange = 2;
cellCell.scale = .5;
cellCell.emissionLongitude = M_PI_2-M_PI_4;
[cellCell setName:@"cellCell"];
cell.emitterCells = @[ cellCell ];
emitterLayer.emitterCells = cells;
emitterLayer.renderMode = kCAEmitterLayerAdditive;
[holderView.layer addSublayer:emitterLayer];
[self.view addSubview:holderView];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment