[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pixel perfect collision detection sugestion



Hi,
To get it "much faster" is always preferable. :)
I'll look a little closer on Numeric then (python is still a rather new
gaming platform for me).

But I still think there should be a pixel perfect implementaion of some sort
in PyGame.

I mean... there would still be the rectangular collision detection for
sprites that doesn't need pixel perfect.

Best Regards
/John
>
> hmm, time flies... but seriously, you're already using Numeric anyway,
> and if you replaced just the part with the nested Python loops with a
> Numeric function, it would probably be much faster, especially if you
> ever have large images with large areas of intersection.
>
> On 9/8/05, John Eriksson <john@xxxxxxxxxxxx> wrote:
> > Hmm...I'm not all that sure that the other code would run
faster..but..well
> > anyway...I thought I at least would post the code. Maybe someone
could find
> > it usefull. :)
> >
> > Most of the times you only need rectangle collisions but every now
and then
> > you really need that pixel perfect touch.
> >
> > /John
> >
> >
> >
> > ---------  Ursprungligt Meddelande --------
> > Från: pygame-users@xxxxxxxx
> > Till: pygame-users@xxxxxxxx <pygame-users@xxxxxxxx>
> > Ämne: Re: [pygame] Pixel perfect collision detection sugestion
> > Datum: 2005/09/08 16:24
> >
> > >
> > > On Thu, 2005-09-08 at 12:48 +0100, John Eriksson wrote:
> > > > I've written a small and fast pixel perfect collision
detection
> > algorithm
> > > > that I thought I might share with everyone.
> > > >
> > > > I've been using this algorithm in several other
languages (C#, Java,
> > Flash)
> > > > with excelent performance.
> > >
> > > >     for r in range(0,rect.height):
> > > >         for c in range(0,rect.width):
> > > >             if hm1[c+x1][r+y1] &
hm2[c+x2][r+y2]:
> > > >                 return 1
> > >
> > > I'm afraid this type of code raises a bit of a red flag for
python.
> > > Although I guess it could be comparable to the flash version?
> > >
> > > This topic comes up every now and then. A year or two ago we
came up
> > > with a Numeric based pixel collision checker. That would run a
bit
> > > faster than this, in fact I'm pretty sure its the reason there
is an
> > > array_colorkey function inside of Surfarray.
> > >
> > > See the old thread here,
> > >
http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/783351
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>
>
>
>