Also do you mean that they should be split into separate threads or
just separate methods?

On May 24, 11:25 am, neuromit <[email protected]> wrote:
> Thank you both for your suggestions, they are really helpful.   I was
> able to optimise my code quite a bit.
>
> My collision detection is pretty primitive, so I'll definitely try to
> improve that.
>
> public boolean detectCollision(Point target, int dist)
> {
>         return (Math.abs(this.x - target.x)<=dist && Math.abs(this.y -
> target.y)<=dist);
>
> }
>
> @Danie, you mentioned that I should split the drawing form the
> animation code; What are the benefits of doing this? as both drawing
> and moving are driven by the same loop?
>
> On May 24, 8: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

Reply via email to