2

in my game thread i'm trying to get high fps- about 60
but only locking the canvas already make it 60 fps the most
this is the code i use-

public void run() 
{   
    super.run();
    int FPS = 60; 
                    final long TPF = 1000 / FPS;
    long startTime;
    long sleepTime;

    while (m_run)
    {   
        startTime = SystemClock.uptimeMillis();

        m_canvas = m_surfaceHolder.lockCanvas();
        if (m_canvas != null)
        {            
        }
        m_surfaceHolder.unlockCanvasAndPost(m_canvas);
        sleepTime = TPF - (SystemClock.uptimeMillis() - startTime);
        Log.d("sleep", String.valueOf((SystemClock.uptimeMillis() - startTime)));
    }

but only by calling lockCanvas and unlockCanvasAndPost i get that 60 ms has been over

4

1 回答 1

3

如果你想要一个非常高的帧速率,比如 60fps,你可能需要使用 OpenGL 而不是 SurfaceView。您仍然可以使用 SurfaceView 获得合理的帧速率(例如〜30fps),每帧绘制的精灵数量从低到中等,但我相信如果不使用 OpenGL,很难做得比这更好。

注意:您对“Log.d”和“String.valueOf”的调用可能会显着降低帧速率,这是一个恼人的 catch-22。

于 2013-05-16T23:10:06.803 回答