I'm currently developing some sort of a game. It's a side-scroller, so a lot of the items are moving - which results in being redrawn. I'm drawing it all on a SurfaceView in another (not UI) thread, but as soon as there are a bit more items to be drawn, the performance drops. Are there any "good" mechanics to improve the performance? Can I somehow do this in multiple threads?
I've thought about creating multiple canvas, and draw a part of my ViewObject list on each one (in different threads), but then I don't know how to "merge" these.
The performance problems began, when I started to add rotating images. I'm rotating them like this:
Matrix matrix = new Matrix();
matrix.preRotate(mRotation, (float) (mResourceBitmaps[mFrame].getWidth()), (float) (mResourceBitmaps[mFrame].getHeight()) / 2f);
Bitmap bmp2 = Bitmap.createBitmap(mResourceBitmaps[mFrame], 0, 0,
mResourceBitmaps[mFrame].getWidth(), mResourceBitmaps[mFrame].getHeight(), matrix, true);
So I'm rotating each bitmap for each animation frame in the code. It became faster when I started to add a BitmapHolder class with a LruCache, which keeps reference of each rotated bitmap (as well as the "standard" bitmaps). But it's still kind of lagging.
Any advices on how this is done in "more professional" games? I'd really like to develop this by myself and not use any 3rd party library, due to the learning factor.
So basically, my question is: How do I draw "a lot" of bitmaps / resources (as they are stored as PNG in my drawable folder) on a single canvas / surfaceview? Or do I have to fall back to multiple view elements representing the objects instead of a SurfaceView?