Touches Moved CAEmitterLayer delayed in dinstance after touch point…

谁都会走 提交于 2019-12-25 00:19:16

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10930668/touches-moved-caemitterlayer-delayed-in-dinstance-after-touch-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!