touchesMoved以不规则间隔调用 [英] touchesMoved called at irregular intervals

查看:284
本文介绍了touchesMoved以不规则间隔调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS制作一个游戏,你通常会在屏幕上拖动大对象。当我在一个实际的iPad / iPhone上运行游戏一段时间(持续拖动对象在屏幕上的圆圈)每隔5分钟左右,拖动对象大约10-30秒

I'm making a game for iOS where you mostly drag big objects across the screen. When I run the game on an actual iPad/iPhone for a while (continuously dragging the object in circles across the screen) every 5 minutes or so the dragged object goes all stuttery for about 10-30 seconds. Then, it goes back to moving silky-smooth.

视觉上,游戏的帧速率下降到15 fps一段时间,但实际上它运行在摇滚固体60 fps所有的时间。但是,我注意到不能平滑移动的只有拖动的对象,而游戏的其余部分都运行顺畅。

Visually, it looks like the game's frame rate dropped to 15 fps for a while, but in actual fact it's running at rock-solid 60 fps all the time. However, I noticed that the only thing that doesn't move smoothly is the dragged object, while the rest of the game is all running perfectly smooth.

这让我相信,口吃是与iOS中的触摸输入有关。所以我开始看着touchesMoved,看到它通常每16毫秒调用一次(因此触摸输入以60 fps运行)。到目前为止这么好。

This led me to believe that the stuttering is related to the touch input in iOS. So I started looking at touchesMoved, and saw that it's normally called every 16 milliseconds (so touch input runs at 60 fps). So far so good.

然后我注意到当对象开始口吃时,touchesMoved开始以奇怪的时间间隔被调用,在8毫秒和50毫秒之间波动

因此,当触摸屏处于这种怪异状态时,有时touchesMoved将在上一次调用后8毫秒被调用,有时它不会呼叫直到上一次呼叫后50毫秒。当然,这使被拖动的对象看起来一切顺滑,因为它的位置是不定期更新的。

So while the touchscreen is in this weird state, sometimes touchesMoved will get called just 8 milliseconds after the previous call, and sometimes it won't get called until 50 ms after the previous call. Of course, this makes the dragged object look all choppy because its position is updated at irregular intervals.

你有什么可能会导致

奖金:

- 无论何时我倾斜屏幕以强制屏幕方向更改,大约70%的时间触摸屏进入上述状态,其中touchesMoved开始被不规则地调用。

-Whenever I tilt the screen to force the screen orientation to change, roughly 70% of the time the touchscreen goes into the aforementioned state where touchesMoved starts being called irregularly. Then after 10-20 seconds it goes back to normal and everything looks smooth again.

- 我在两个iPad和两个iPhone上进行了测试,iOS 6和7 ,并且所有这些设备都会出现此问题。

-I've tried this on two iPads and two iPhones, with iOS 6 and 7, and the issue appears in all of these devices.

- OpenGLES视图用于显示图形。它使用 CADisplayLink 同步到显示刷新率。

-An OpenGLES view is used to display the graphics. It syncs to the display refresh rate using CADisplayLink.

- 我用来测试这个的Xcode项目由unity3d游戏开发工具生成,但我发现几个非统一的游戏,出现相同的问题。这似乎是一个全系统的问题。注意我使用 CFAbsoluteTimeGetCurrent 测量objective-c中的时间,完全在unity之外。

-The Xcode project I'm using to test this has been generated by the unity3d game development tool, but I've found several non-unity games where the same issue appears. this appears to be a system-wide problem. note I'm measuring the timings in objective-c using CFAbsoluteTimeGetCurrent, completely outside unity.

推荐答案

这不是Unity中的错误。

This is not a bug in Unity.

操作系统内部出现错误状态,触摸拖动信息停止流畅。有时你会在一个框架中获得多个更新,有时你不会得到。

Something inside the OS is getting into a bad state and the touch-drag messages stop flowing smoothly. Sometimes you'll get multiple updates in a frame and sometimes you'll get none.

这个问题不会发生在iPhone4或更低,或者如果游戏运行30Hz帧速率。

The issue does not happen on iPhone4 or below, or if the game is running at 30Hz frame rate.

我在使用我在之前公司工作时写的内部引擎时遇到了这个错误。它首先表现自己在升级UI系统的拼字游戏类游戏,在那里你拖动在屏幕上的瓷砖。这是非常奇怪的,我从来不能确定准确的复制步骤,但他们似乎是时间相关的,以某种方式。

I experienced this bug while using an in-house engine I'd written while working at a previous company. It first manifest itself after upgrading the UI system of a scrabble genre game, where you drag the tiles about on the screen. This was utterly bizarre, and I was never able to pin down the exact reproduction steps, but they seem to be timing related, somehow.

它也可以看到愤怒鸟(除非他们现在已经固定),以及市场上的各种其他游戏,基本上任何具有触摸拖动滚动或移动。对于愤怒的小鸟,只是进入一个水平,开始滚动横向。大多数时候,它会是柔滑的,但也许1在10倍,它会笨重。重新启动应用程式,然后再试一次。

It can also be seen on Angry Birds (unless they've fixed it by now), and a variety of other games on the market, basically anything with touch-drag scrolling or movement. For Angry Birds, just go into a level and start scrolling sideways. Most of the time it'll be silky smooth, but maybe 1 in 10 times, it'll be clunky. Re-start the app and try again.

一种解决方法是将输入更新频率降至30Hz几帧。这使操作系统的内部结构不知何故,并给它时间伸直自己,所以当你把它回到60Hz,它再次顺利运行。

A workaround is to drop the input update frequency to 30Hz for a few frames. This jolts the internals of the OS somehow and gives it time to straighten itself out, so when you crank it back up to 60Hz, it runs smoothly again.

您检测到已输入错误状态。

Do that whenever you detect that the bad state has been entered.

这篇关于touchesMoved以不规则间隔调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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