为什么触摸事件破坏我Android的帧率? [英] Why are touch events destroying my Android framerate?
问题描述
我正在开发一个游戏为Android。它有很多事情,但运行相当流畅。即,当然,直到用户触摸屏幕。
I'm developing a game for Android. It's got a lot going on but is running reasonably smoothly. That is, of course, until the user touches the screen.
虽然他们为之动容,的onTouchEvent
被称为(与行动= ACTION_MOVE
, X = 0
和 Y = 0
)大约每10毫秒这似乎是一个相当高的优先级,因为它完全抹杀帧率。当触摸结束帧率返回到其不错的状态。
While they're touching it, onTouchEvent
is called (with action = ACTION_MOVE
, x = 0
and y = 0
) roughly once every ten milliseconds at what appears to be a fairly high priority, as it absolutely obliterates the framerate. As soon as the touch ends the framerate returns to its nice state.
我试过
- 有
的onTouchEvent
处理输入的游戏照常 - 有
的onTouchEvent
返回真
马上 - 没有
的onTouchEvent
在所有实施
- having
onTouchEvent
handle input for the game as usual - having
onTouchEvent
returntrue
straight away - not having
onTouchEvent
implemented at all
该问题仍然存在,在所有三种情况。
The problem persists in all three situations.
有没有人遇到过吗?有没有一种方法,以减少在其中产生 ACTION_MOVE
事件的速度,或以确保他们时,才会有实际运动产生的,或者使用轮询方法,只是获得所述触摸的当前位置?甚至只是一种方法来完全禁用呢?
Has anyone encountered this? Is there a way to reduce the rate at which ACTION_MOVE
events are generated, or to ensure that they're only generated when there is actual movement, or use a polling method that just gets the current location of the touch? Or even just a way to disable it entirely?
推荐答案
<一个href="http://groups.google.com/group/android-developers/browse%5Fthread/thread/39eea4d7f6e6dfca">Read此线程。基本上你想睡觉事件线程,否则系统将泵很多事件(的x,y和pressure总有一些运动正在进行),您需要处理。
Read this thread. Basically you want to sleep the event thread since otherwise the system will pump a lot of events (between x,y and pressure there is always some movement going on) that you need to handle.
这篇关于为什么触摸事件破坏我Android的帧率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!