我有以下代码:
public boolean onTouchEvent(MotionEvent event) {
fingerSize = event.getSize();
fingerPosX = event.getX();
fingerPosY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
start = true;
break;
}
}
return true;
}
我使用了fingerSize、fingerPosX和fingerPosY这三个变量来画一个圆:
canvas.drawCircle(fingerPosX, fingerPosY, fingerSize
* fingersizeCorrection, paint);
所以基本上,当我用手指在屏幕上移动时,圆圈会跟随我的手指。问题是圆圈在试图跟随我的手指时的运动非常不稳定。
如何改进以使其更加流畅?
这一切都发生在 SurfaceView 中,我还添加了这样的 fps 限制器:
int FRAMES_PER_SECOND = 60;
int SKIP_TICKS = 1000/FRAMES_PER_SECOND;
long next_game_tick = timer.getElapsedTimeMil();
int sleep_time = 0;
next_game_tick += SKIP_TICKS;
sleep_time = (int) (next_game_tick-timer.getElapsedTimeMil());
if(sleep_time >= 0){
try {
Thread.sleep(sleep_time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
}