出于某种原因,当我在屏幕上(在模拟器上)移动鼠标时,我的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帧的平均值),触摸是否正在触摸屏幕(来自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
答案 0 :(得分:6)
如果您在Windows上运行模拟器,那么我认为this会解释它:
中的性能选项说明 视窗强>
...另外,请记住Microsoft Windows NT还使用了额外的优先权 基于其他的调整(通常为2) 事件,例如暂时提升a 线程返回时的优先级 从a返回时的I / O调用 用户模式子系统调用,或何时 接收键盘输入。
我多次见过这种效果。我只是使用ProcessExplorer看了一下模拟器:虽然我不能肯定地说,它看起来像模拟器在一个Windows线程下运行。除非你在真正的Android设备上看到类似的性能提升,否则我认为这是Windows操作系统的影响,而不是AndroidOS。
答案 1 :(得分:0)
我遇到了同样的问题,即使它不那么引人注目也会出现在手机上。我想我知道发生了什么。我使用带有postDelayed(...)的Handler作为我的主循环。我想绘图首先以某种方式阻止消息队列,然后touchevent导致应用程序在下一次计划检查之前检查队列。为什么问题在某种程度上随机发生是一个谜。
我通过在绘图之前将postDelayed-line放在Runnable中来解决它。
这肯定与Windows无关。