Is a negative start to CAEmitterLayer possible?

I am trying to get CAEmitterLayer and CAEmitterCell to start their animation somewhere in the middle of their parent duration. Is it even possible? I tried to play with the beginTime and timeOffset , but I can't get this to work.

Added code for posterity: (let's say I want the emitter to start from 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 the animation starts from the moment when the emitter generates particles.

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

Say I have a CAEmitterLayer that animates rain, so I'm setting up cells to create a falling animation that starts from the top of the screen. At the start of rendering, I don’t want to start with a state that "it is not raining yet." I want to start when the screen is already covered in rain.

+6
source share
1 answer

beginTime not relevant at this time. You need to capture the current time relative to the temporary space of the current layer, which you can get using the CACurrentMediaTime() function. So, in your case, you would do something like this:

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

Source: https://habr.com/ru/post/923336/


All Articles