4

I'm planning on implementing a new set of figures in my game: plain circles. The number of drawn sprites (in this case circles) starts with 2-3, and can go up endlessly (potentially). The maximum will probably be around 60 though. In total there will have to be 5 types of circles, each with a different color and probably size too. Now seeing as I won't implement it until monday I thought I'd ask it at stackoverflow.

Does anybody already know which method is faster?

Kara
  • 6,115
  • 16
  • 50
  • 57
SBoss
  • 8,845
  • 7
  • 28
  • 44

1 Answers1

8

Bitmaps are almost always faster than any kind of draw. With the right preparation drawing a bitmap is simply dumping memory to the screen. Drawing a circle involves a significant number of calculations, including anti-aliasing. I presented a paper which covered this at JavaOne 2009, but papers that old seem to have been removed from the site.

It does depend on how big your bitmap would need to be, but for sizes under 10 pixels bitmap sprites are much faster than even simple graphic operations like drawing crosses and lines. You also need to make sure that your sprite won't require any kind of transform when it is drawn, and that it is a form compatible with the screen memory.

If every circle is to be a different color or thickness, or worse a different size, then that's another matter. The cost of creating each bitmap would outweigh the savings.

You should also remember the first rule of optimization: don't do it unless you have to.

DJClayworth
  • 26,349
  • 9
  • 53
  • 79
  • Assuming the bitmaps are 40*40 pixels, including transparency but no transformations (simply calling canvas.drawBitmap(staticBitmap, x,y,null), would it still be worth it? Or are there other preparations? I'll also probably set down the rgb thing when decoding as they'll be one-color circles. – SBoss Aug 18 '11 at 15:26
  • That's a little larger than anything I tested. But this is a perfect case where your own performance test will tell you the answer. – DJClayworth Aug 18 '11 at 16:16