Pregunta

I have a animated CAEmitterLayer with CAEmitterCell and the animation runs well with

 fireEmitter = (CAEmitterLayer*)self.layer; 
    fireEmitter.emitterPosition = CGPointMake(50, 50);
    fireEmitter.emitterSize = CGSizeMake(10, 10);

    CAEmitterCell* fire = [CAEmitterCell emitterCell];
    ...
    [fire setName:@"fire"];

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
    anim.path = theBezierPath.CGPath;
    anim.calculationMode = kCAAnimationCubicPaced;
    anim.repeatCount = HUGE_VALF;
    anim.duration = 12.0;
    [self.layer addAnimation:anim forKey:@"fire"];

my bezier path is closed and forms a "8" out of four position points. with my timerFunction I try to get the position of the CAEmitterLayer every second. for that I use

-(CGPoint)getEmitterPosition
{
    return fireEmitter.emitterPosition;
}

in the emitter class and

CGPoint emitterPosition = [self.ParticleEmitterView getEmitterPosition];
NSLog(@"%f / %f", emitterPosition.y, emitterPosition.y);

from the timer function.

But when the animation is running the console spits out the same positio every call allthough the emitter is running over the screen.

why is that and how could I get the emitter position of an animated CAEmitterLayer/Cell?

¿Fue útil?

Solución

Have you tried querying the CAEmitterLayer's presentationLayer property and asking the resulting CALayer for its position? The presentation layer should give you access to the properties of the layer as they appear on the screen during the animation, while the emitter layer will give you the properties as they will be at the end of all current animations.

This is due to the model-view separation inherent in Core Animation's rendering architecture.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top