[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pixel perfect collision detection sugestion
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] &amp; 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
>
>
>
>
>