Drawing a bitmap is going to be faster than drawing a circle. Drawing a circle requires making a curved path and filling it. Drawing an anti-aliased circle will be a *lot* slower than drawing a bitmap.
Basically you can assume, at least for software rendering, that the speed of operations is: (1) Rect fills are the fastest. (2) Bitmaps (that aren't scaled or otherwise transformed) are a close second. (3) Everything else is a lot slower. You'll notice that pretty much all of the Android UI itself is drawn with rect fills and bit blits. This is why. :) (Text is a special case of drawing bitmaps.) That said, profiling is still always the the best indication of what is slow. On Tue, May 24, 2011 at 5:33 AM, Daniel Drozdzewski < [email protected]> wrote: > Stuart, > > There are few fixes straight away: > > - Have a predefined Paint object for your dots and use that instead > of creating new Paint object each time you enter drawDots() > - assign dots.size() to a local variable and keep testing that > variable in the for loop, rather than calling size() method with each > operation > - don't detect collisions in your drawing code > - worth testing whether Canvas.drawBitmap() (cached bitmap of a dot) > could be quicker than Canvas.drawCircle(); first one only copies > memory byte by byte, while second does some computation too > - and finally as String said: profile it > > > Then you have to think: > - how complex is your collision detection? it has to be optimised and > you should not be iterating through all dots testing for potential > collision with PacMan; if you think about it, your dots don't move and > PacMan moves incrementally; there are few clever strategies that you > could use; in general collision detection optimisation strategies are > not trivial, but I am sure you could find something that would work > well for you and would not be too hard to implement; > > have a look here as an entry to possible ideas: > http://en.wikipedia.org/wiki/Collision_detection > > > > > On Tue, May 24, 2011 at 12:57 PM, neuromit <[email protected]> > wrote: > > I'm writing a pacman style game that has a lot of things to be drawn, > > namely, the dots that pacman likes to eat. > > > > I'm finding that the drawing of the dots is greatly hampering the > > performance of the game. If I turn them off my app consumes much fewer > > cpu cycles than if they are left on. > > > > here is the code i'm using to draw the dots: http://paste2.org/p/1432169 > > > > void drawDots(Canvas c) { > > if (!this.drawDots) > > return; > > > > Paint p = new Paint(mPaint); > > p.setColor(this.dotColor); > > for (int i=0; i<dots.size(); i++) > > { > > Dot d = dots.get(i); > > if (this.pacdroid.detectCollision(d)) > > d.disableDot(); > > if (d.enabled) > > c.drawCircle(d.x, d.y,d.r, p); > > //dots.get(i).draw(c, p); > > } > > } > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > For more options, visit this group at > > http://groups.google.com/group/android-developers?hl=en > > > > -- > Daniel Drozdzewski > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

