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

Re: [pygame] Pixel perfect collision detection sugestion



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:
> > &gt; I've written a small and fast pixel perfect collision detection
> algorithm
> > &gt; that I thought I might share with everyone.
> > &gt;
> > &gt; I've been using this algorithm in several other languages (C#, Java,
> Flash)
> > &gt; with excelent performance.
> >
> > &gt;     for r in range(0,rect.height):
> > &gt;         for c in range(0,rect.width):
> > &gt;             if hm1[c+x1][r+y1] &amp;amp; hm2[c+x2][r+y2]:
> > &gt;                 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
> >
> >
> >
> >
> >
> 
>