在模拟器上,当我按住左键并且移动鼠标时,FPS明显提高。通常情况下我的游戏非常卡顿,但如果我触摸屏幕(只要我一直在触摸的同时保持移动鼠标),它就会非常流畅。
我尝试在onTouchEvent中休眠20ms,但看起来没有任何区别。
这是我在onTouchEvent中使用的代码:
// events when touching the screen
public boolean onTouchEvent(MotionEvent event)
{
int eventaction = event.getAction();
touchX=event.getX();
touchY=event.getY();
switch (eventaction)
{
case MotionEvent.ACTION_DOWN:
{
touch=true;
}
break;
case MotionEvent.ACTION_MOVE:
{
}
break;
case MotionEvent.ACTION_UP:
{
touch=false;
}
break;
}
/*try
{
AscentThread.sleep(20);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}*/
return true;
}
在logcat日志中,FPS是当前的fps(最近20帧的平均值),touch表示屏幕是否被触摸(来自onTouchEvent)。到底发生了什么?有其他人遇到过这种奇怪的行为吗?
Logcat日志:
12-21 19:43:26.154: INFO/myActivity(786): FPS: 31.686569159606414 Touch: false
12-21 19:43:27.624: INFO/myActivity(786): FPS: 19.46310293212206 Touch: false
12-21 19:43:29.104: INFO/myActivity(786): FPS: 18.801202175690467 Touch: false
12-21 19:43:30.514: INFO/myActivity(786): FPS: 21.118295877408478 Touch: false
12-21 19:43:31.985: INFO/myActivity(786): FPS: 19.117397812958878 Touch: false
12-21 19:43:33.534: INFO/myActivity(786): FPS: 15.572571858239263 Touch: false
12-21 19:43:34.934: INFO/myActivity(786): FPS: 20.584119901503506 Touch: false
12-21 19:43:36.404: INFO/myActivity(786): FPS: 18.888025905454207 Touch: false
12-21 19:43:37.814: INFO/myActivity(786): FPS: 22.35722329083629 Touch: false
12-21 19:43:39.353: INFO/myActivity(786): FPS: 15.73604859775362 Touch: false
12-21 19:43:40.763: INFO/myActivity(786): FPS: 20.912449882754633 Touch: false
12-21 19:43:42.233: INFO/myActivity(786): FPS: 18.785278388997718 Touch: false
12-21 19:43:43.634: INFO/myActivity(786): FPS: 20.1357397209596 Touch: false
12-21 19:43:45.043: INFO/myActivity(786): FPS: 21.961138432007957 Touch: false
12-21 19:43:46.453: INFO/myActivity(786): FPS: 22.167196852834273 Touch: false
12-21 19:43:47.854: INFO/myActivity(786): FPS: 22.207318228024274 Touch: false
12-21 19:43:49.264: INFO/myActivity(786): FPS: 22.36980559230175 Touch: false
12-21 19:43:50.604: INFO/myActivity(786): FPS: 23.587638823252547 Touch: false
12-21 19:43:52.073: INFO/myActivity(786): FPS: 19.233902040593076 Touch: false
12-21 19:43:53.624: INFO/myActivity(786): FPS: 15.542190150440987 Touch: false
12-21 19:43:55.034: INFO/myActivity(786): FPS: 20.82290063974675 Touch: false
12-21 19:43:56.436: INFO/myActivity(786): FPS: 21.975282007207717 Touch: false
12-21 19:43:57.914: INFO/myActivity(786): FPS: 18.786927284103687 Touch: false
12-21 19:43:59.393: INFO/myActivity(786): FPS: 18.96879004217992 Touch: false
12-21 19:44:00.625: INFO/myActivity(786): FPS: 28.367566618064878 Touch: false
12-21 19:44:02.113: INFO/myActivity(786): FPS: 19.04441528684418 Touch: false
12-21 19:44:03.585: INFO/myActivity(786): FPS: 18.807837511809065 Touch: false
12-21 19:44:04.993: INFO/myActivity(786): FPS: 21.134330284993418 Touch: false
12-21 19:44:06.275: INFO/myActivity(786): FPS: 27.209688764079907 Touch: false
12-21 19:44:07.753: INFO/myActivity(786): FPS: 19.055894653261653 Touch: false
12-21 19:44:09.163: INFO/myActivity(786): FPS: 22.05422794901088 Touch: false
12-21 19:44:10.644: INFO/myActivity(786): FPS: 18.6956805300596 Touch: false
12-21 19:44:12.124: INFO/myActivity(786): FPS: 17.434180581311054 Touch: false
12-21 19:44:13.594: INFO/myActivity(786): FPS: 18.71932038510891 Touch: false
12-21 19:44:14.504: INFO/myActivity(786): FPS: 40.94571503868066 Touch: true
12-21 19:44:14.924: INFO/myActivity(786): FPS: 57.061200121138576 Touch: true
12-21 19:44:15.364: INFO/myActivity(786): FPS: 62.54377946377936 Touch: true
12-21 19:44:15.764: INFO/myActivity(786): FPS: 64.05005071818726 Touch: true
12-21 19:44:16.384: INFO/myActivity(786): FPS: 50.912951172948155 Touch: true
12-21 19:44:16.874: INFO/myActivity(786): FPS: 55.31242053078078 Touch: true
12-21 19:44:17.364: INFO/myActivity(786): FPS: 59.31625410615102 Touch: true
12-21 19:44:18.413: INFO/myActivity(786): FPS: 36.63504170925923 Touch: false
12-21 19:44:19.885: INFO/myActivity(786): FPS: 18.099130467755923 Touch: false
12-21 19:44:21.363: INFO/myActivity(786): FPS: 18.458978222946566 Touch: false
12-21 19:44:22.683: INFO/myActivity(786): FPS: 25.582179409330823 Touch: true
12-21 19:44:23.044: INFO/myActivity(786): FPS: 60.99865521942455 Touch: true
12-21 19:44:23.403: INFO/myActivity(786): FPS: 74.17873975470984 Touch: true
12-21 19:44:23.763: INFO/myActivity(786): FPS: 64.25663040460714 Touch: true
12-21 19:44:24.113: INFO/myActivity(786): FPS: 62.47483457826921 Touch: true
12-21 19:44:24.473: INFO/myActivity(786): FPS: 65.27969529547072 Touch: true
12-21 19:44:24.825: INFO/myActivity(786): FPS: 67.84743115273311 Touch: true
12-21 19:44:25.173: INFO/myActivity(786): FPS: 73.50854551357706 Touch: true
12-21 19:44:25.523: INFO/myActivity(786): FPS: 70.46432534585368 Touch: true
12-21 19:44:25.873: INFO/myActivity(786): FPS: 69.04076953445896 Touch: true