我正在开发一款安卓游戏,并使用SurfaceView。我有一个将被调用每16毫秒(我希望能有60fps的)SurfaceHolder.lockCanvas()为我的游戏应用程序花费太长时间
public void myDraw(SurfaceHolder holder) {
Canvas c = null;
long start = System.currentMillis();
try {
synchronized(holder) {
c = holder.lockCanvas();
if (c != null) {
c.drawColor(Color.GREEN);
}
}
} finally {
if (c != null) {
holder.unlockCanvas(c);
}
}
Log.i(TAG, "total time:" + (System.currentMillis() - start));
}
当我运行我的应用程序的方法,从logcat的输出是:
total time:30
total time:23
total time:6
total time:39
total time:17
为什么的锁定/解锁画布需要太多时间?有没有更好的方法来解决我的问题? (即拥有60 fps的应用程序)
谢谢!