I'm animating some particles and rather than have then just disappear at the end of their lifetime I'd like them to fade out.
I have a CAEmitterCell
defined with a lifetime of 35.0. I don't want to just have the particle fade out over the full duration of the particle lifetime. I only want it to fade out at the end. Perhaps the last 2 or 3 seconds.
For the CAEmitterCell
's color
property, set the alpha value to lifetime * alphaSpeed
(where alphaSpeed is -1.0/fadeOutDuration).
So for a lifetime of 35.0 and a fadeOutDuration of 2.0, alphaSpeed would be -0.5, and alpha would be 17.5.
There are a couple caveats:
CAEmitterCell
's color property using a CGColorRef
created with CGColorCreateCopyWithAlpha
. Both UIColor
and CGColorCreate
clamp their values to a maximum of 1.0. For whatever reason, CGColorCreateCopyWithAlpha
doesn't.Just came across this in the docs which might point in the right direction:
name The name of the cell.
@property(copy) NSString *name Discussion The cell name is used when constructing animation key paths that reference the cell. Defaults to nil.
For example, adding an animation to a cell’s enclosing layer with the a keypath such as emitterCells.myCellName.redRange would animate the redRange propery of the cell in the layer’s emitterCells array with the name myCellName.
Availability Available in Mac OS X v10.6 and later. Declared In CAEmitterCell.h
I gather you still add the animation to the layer but with a key path that references a part of that layer - in this case the cell's property. Is there an alpha property exposed for cells?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With