Search code examples
androidsurfaceviewframe-rategame-loop

Why can't my SurfaceView's game loop run a decent FPS?


I've cobbled together a simple game loop, mostly using the techniques that seem be be prevelent, particually in the Killer Game Programming in Java book and in this tutorial I just found: Here Just a simple, timed gameloop with a back buffer.

The problem is that it won't redraw the screen at a good FPS. The best I can get out of my Motorola Xoom is 15FPS, aiming for 24.

If I half the size of the back buffer, the speed shoots up considerably so I'm guesing the problem may have something to do with utilizing the screen on the Xoom ( the size of my SurfaceView is 1280x727 )... yet other games seen to run perfectly well at the same size.

I don't have any other devices to test on so I'm a little stuck for what to do at the moment.

What am I doing wrong/missing/ignorant of?


Solution

  • Maybe that the pixel formats of your bitmap and the surface differ, causing a conversion whenever you draw the bitmap? That would certainly induce overhead. Try and experiment with SurfaceHolder.setFormat() to see if that helps.

    Since your bitmap is using Bitmap.Config.ARGB_8888, you could try to set the surface holder format to PixelFormat.RGBA_8888. Or, if you can, then try and use Bitmap.Config.RGB_565, and PixelFormat.RGB_565.