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"];
Pregunta
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?
Solución
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"];
Otros consejos
When you init the self.emitter
with a new cell,the object will be retained,so ..when you change the cell.yAcceleration
with a timer,the cell of self.emitter
can not be changed,self.cell.yAcceleration
has been changed already.So, you should use the key path of self.emitter
.