Pregunta

I stumbled from one problem to another one: Solving the first problem, now my particle trail is delayed way behind the touch position when a finger moves over the screen.

it worked great when I was initialising the CAEmitterLayer by overwriting

+ (Class) layerClass 
{
    //configure the UIView to have emitter layer
    return [CAEmitterLayer class];
}

and the initializing with

fireEmitter = (CAEmitterLayer*)self.layer; 

I changed that to

fireEmitter = [CAEmitterLayer layer];
fireEmitter.frame = self.bounds;
[self.layer addSublayer:fireEmitter];

and now the emitter cells follow the moved touch point like geishas in a distance

why is that? because I chnaged the layer where the emitter is emitting now? please help! thnx

¿Fue útil?

Solución

You're only going to get so many touch events per second, and you're only able to draw to the screen a certain number of times per second. Let's do some math.

Suppose you can move your finger diagonally across the entire screen in 166ms (swiping pretty fast). Suppose also that you're rendering enough particles to slow the device from 60 FPS to 30 FPS (33ms per render cycle). That means you only get about 5 touch callbacks in the time it takes to swipe the screen. That, in turn, means that you're only getting a touch event for every 100 pixels or so that your finger moves.

So, even if you assume that there's zero lag in the touch position you receive (there isn't), you only get them often enough that you there will almost always be some visible lag. The only way to reduce this lag is to increase your frame rate (by using fewer/smaller particles or switching to a technology that scales better in the number of particles you have, such as OpenGL). You should use Instruments first to verify that frame rate is, in fact, your problem.

NOTE: I measured the effect of using [CATransaction setDisableActions:YES] when setting the emitter position and didn't see a difference, so this is not purely a matter of implicit animations being used.

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