cocos2d - is it faster to draw a primitive shape (e.g. ccDrawCircle, drawDot) or draw a sprite?

StackOverflow https://stackoverflow.com/questions/23584550

  •  19-07-2023
  •  | 
  •  

Question

I have to draw a number sprites and also a very large circle, and I'm wondering if is it better to draw that circle using ccDrawCircle, or to make a circle sprite and draw it as a regular sprite? In terms of memory, I'd be using up a lot to store basically nothing but a giant circle; but is it faster to do all the drawing as one batch? What if I had to split it up into two batches, one for the circle and another for the other sprites? Is it faster to draw a primitive shape or to draw a sprite?

Was it helpful?

Solution

ccDraw* methods aren't batch-drawn and meant for debugging, they are not particularly efficient.

CCDrawNode is a much better option as it can batch-draw primitives, but it doesn't allow primitives to be removed without recreating them all.

Batched sprites are usually the best option. How much this affects fps depends on your use case and targeted devices. Problem is they don't "scale" well, so it's best to have each required size of a shape as a separate image. On the other hand you can tint (colorize) a grayscale image in order to have more color variety without having to have each shape with different colors as separate images.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top