我正在開發一款安卓遊戲,並使用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的應用程序)
謝謝!