There are two birthRate
properties in play here.
Each
CAEmitterCell
has abirthRate
property.
This is the hardwired birthrate for that cell.The
CAEmitterLayer
has abirthRate
property.
This is a multiplier applied to each cell'sbirthRate
property to derive an actual birthrate in play.
Your code is confusing the two - you set the cells' birthRate to zero in your initialisation, but change the layer's birthRate multiplier in your toggle method.
Two solutions...
1 - in toggleOn:
set the cell's birthRate, not the layer's multiplier:
- (void) toggleOn:(bool)on
{
CAEmitterCell* emitterCell = [self.touchEmitter.emitterCells objectAtIndex:0];
[emitterCell setBirthRate:on? 300 : 0];
}
2 - in your initialisation, set the cell's birthrate to nonzero:
touch.birthRate = 1.0;
The multiplier you are using in toggleOn
will then apply to this number.