3

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?

Stretch
  • 173
  • 4
  • 10
  • 1
    Profile! Traceview is your friend. http://developer.android.com/guide/developing/debugging/debugging-tracing.html After you've profiled update your question with more information – smith324 Aug 06 '11 at 15:16
  • What I could make out from the profiler put 98%+ of the load on drawing the buffer to the SurfaceView canvas. – Stretch Aug 12 '11 at 19:38

2 Answers2

10

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.

olivierg
  • 10,200
  • 4
  • 30
  • 33
  • This was bang on the money. Thank you. I changed the format of my buffer bitmap to RGB_565 and it runs smoothly up to about 50 frames per second. – Stretch Aug 12 '11 at 22:58
  • Good! That said, beware of possible compatibility problems. If you change the default pixel format, then I recommend that you test on several devices. It should be ok in your case I think, but I've already had a couple of color problems when doing similar stuff with OpenGL. – olivierg Aug 13 '11 at 09:43
  • Your answer here helped me solve an unrelated problem, so +1. By applying `PixelFormat.RGBA_8888` in my `SurfaceView` I eliminated an annoying colour banding on gradients due to the `SurfaceView` evidently not being ARGB_8888 by default. – Trevor Oct 15 '11 at 20:33
0

Going to need some code but I suspect you are not using any threads? If you are not using Threads then you program will be unstable and crash quite often due to all your processing being on the same Thread

In short make sure you have created a new Thread, I use OpenGL which requires a thread anyway so that may be your best route to go down

Chris
  • 1,766
  • 1
  • 21
  • 36
  • Yes. I'm using threads.. I didn't post any code becuase my implementation is pretty much exactly as the link specified. – Stretch Aug 06 '11 at 14:24