CAEmitterLayer negative beginTime possible?

1k Views Asked by At

I'm trying to get CAEmitterLayers and CAEmitterCells to start their animation from somewhere in the middle of their parent's duration. Is this possible at all? I tried playing with the beginTime and timeOffset properties but I can't seem to get this working.

Added some code for posterity: (lets say I want the emitter to start at the 5th second)

    CAEmitterLayer *emitter = [CAEmitterLayer new];
    // emitter.beginTime = -5.0f; // I tried this
    // emitter.timeOffset = 5.0f; // I also tried this, with beginTime = 0.0, and with beginTime = AVCoreAnimationBeginTimeAtZero
    /* set some other CAEmitterLayer properties */

    CAEmitterCell *cell = [CAEmitterCell new];
    // cell.beginTime = -5.0f; // Then I saw that CAEmitterCell implements CAMediaTiming protocol so I tried this
    // cell.timeOffset = 5.0f; // and this
    /* set some other CAEmitterCell properties */

    emitter.emitterCells = @[cell];
    [viewLayer addSubLayer:emitter];

But still the animation starts from where the emitter generates the particles.

Edited again to explain what I'm trying to do:

Lets say I have a CAEmitterLayer that animates rain, so I setup the cells to do a "falling" animation that starts from the top of the screen. During the start of rendering, I don't want to start in a state that's "not raining yet". I want to start where the screen is already covered with rain.

1

There are 1 best solutions below

6
On

The beginTime isn't relative to now. You need to grab the current time relative to the current layer time space, which you can get by using the CACurrentMediaTime() function. So in your case, you'd do something like this:

emitter.beginTime = CACurrentMediaTime() + 5.f;