Skip to content Skip to sidebar Skip to footer

How To Draw Game On Android Canvas With Lots Of Primitives

I draw a lot of lines rectangles each frame in my game - it's a recreation of an old school handheld electronic game. The ones that had crude dot matrix display for the main game a

Solution 1:

SurfaceHolder.unlockCanvasAndPost() actually does page flipping on the Surface, so even if the previous frame wasn't cleared out you'd get the 2nd oldest frame, not the one you just drew. and doing lock() on a surface instantiates a new canvas each time which probably is doing the clearing in its constructor.

You're better off drawing into a Bitmap like someone suggested and then drawBitmap on the canvas each time you want to present the image to the display. You can aquire a canvas from a bitmap to draw into it

and like someone else suggested (very ambiguously), you can generate sprites for the dot matrix display and draw those directly from a cache of bitmaps rather then draw with primitive commands. ie for a dot matrix calculator you could generate all 0-9 into 10 bitmaps and simply blit them on the canvas rather then calling a set of drawLine/Rect operations.

if the above are still too slow there still is opengl, which takes advantage of hardware acceleration

Solution 2:

Why not to go for Sprites?

Post a Comment for "How To Draw Game On Android Canvas With Lots Of Primitives"