Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing CAEmitterCell properties of CAEmitterLayer after emission starts

When I first set up the emitter I can do this:

self.cell = [CAEmitterCell emitterCell];
self.cell.yAcceleration = 20;
...
self.emitter.emitterCells = [NSArray arrayWithObjects:self.cell,nil];

But say I create a timer that fires 5 seconds later, and I do this:

- (void)timerFired
{
    self.cell.yAcceleration = -10;

}

The timer fires, but the yAcceleration of the CAEmitterCell does not get changed. Or at least nothing changes in the particle emission on screen. How can I get a CAEmitterCell to respect changes I make to its properties?

like image 312
soleil Avatar asked Oct 24 '13 18:10

soleil


1 Answers

This is not real obvious, but here's the solution:

[self.emitter setValue:[NSNumber numberWithFloat:-10.0]
               forKeyPath:@"emitterCells.cell.yAcceleration"];

Where "cell" is the name given here:

[self.cell setName:@"cell"];
like image 60
soleil Avatar answered Nov 07 '22 18:11

soleil