小编rac*_*min的帖子

SurfaceHolder.lockCanvas()对我的游戏应用来说需要太长时间

我正在开发一款安卓游戏,我正在使用SurfaceView.我有一个方法,每16ms调用一次(我希望有60fps)

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));
}
Run Code Online (Sandbox Code Playgroud)

当我运行我的应用程序时,LogCat的输出是:

total time:30
total time:23
total time:6
total time:39
total time:17
Run Code Online (Sandbox Code Playgroud)

为什么锁定/解锁画布需要花费太多时间?有没有更好的方法解决我的问题?(也就是说,有一个60 fps的应用程序)

谢谢!

android canvas surfaceholder

3
推荐指数
1
解决办法
2704
查看次数

标签 统计

android ×1

canvas ×1

surfaceholder ×1