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

Re: [pygame] Pixel perfect collision detection sugestion



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