触摸后,触摸的CAEmitterLayer延迟延迟. [英] Touches Moved CAEmitterLayer delayed in dinstance after touch point...

查看:160
本文介绍了触摸后,触摸的CAEmitterLayer延迟延迟.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个问题跌落到另一个问题:解决

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.

当我通过覆盖初始化CAEmitterLayer时,效果很好

it worked great when I was initialising the CAEmitterLayer by overwriting

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

并使用

fireEmitter = (CAEmitterLayer*)self.layer; 

我将其更改为

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

那是为什么?因为我更改了发射器现在发射的层? 请帮忙! thnx

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

推荐答案

您每秒仅会收到如此多的触摸事件,并且每秒只能在屏幕上绘制一定次数.让我们做一些数学.

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.

假设您可以在166毫秒内沿整个屏幕对角移动手指(快速滑动).还假设您渲染的粒子足够使设备从60 FPS减慢到30 FPS(每个渲染周期33ms).这意味着您在滑动屏幕时仅获得约5个触摸回调.相应地,这意味着您每100像素左右只有一次触摸事件,所以手指会移动.

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.

因此,即使您假设所接收的触摸位置的时滞为零(没有),您也只能经常得到它们,以至于几乎总会有一些可见的时滞.减少这种滞后的唯一方法是提高帧速率(通过使用更少/更小的粒子或切换为可更好地缩放粒子数量的技术,例如OpenGL).您应该首先使用Instruments来验证帧速率确实是您的问题.

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.

注意:我测量了设置发射器位置时使用[CATransaction setDisableActions:YES]的效果,但没有发现差异,因此这不完全是使用隐式动画的问题.

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.

这篇关于触摸后,触摸的CAEmitterLayer延迟延迟.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆