[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pixel perfect collision detection sugestion
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Pixel perfect collision detection sugestion
- From: Peter Nicolai <pnicolai@xxxxxxxxx>
- Date: Thu, 8 Sep 2005 13:07:10 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 08 Sep 2005 13:08:21 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gYd2opTyn84rfAj3j6VgRFsG6UhAoPZ3lg6Dn7HLSlCiFi3poNUcjfFAsXhSumvD/RIAttaUfdTINvPyr6CXOxJRUFRgyo5+D5pjSSB4nr8KWBaYH94j6MC6M7V6uF5+Sw4GZ5mZpKYBLMCoZ3PVLW7jVDPQwRNckxOMXpBRnXI=
- In-reply-to: <20050908160536.3734AE8166@k2.scorpionshops.com>
- References: <20050908160536.3734AE8166@k2.scorpionshops.com>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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] &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
> >
> >
> >
> >
> >
>
>