Pixel perfect collision detection between Rabbyt sprites

55 views
Skip to first unread message

Kiril Zvezdarov

unread,
May 15, 2012, 10:09:52 AM5/15/12
to rab...@googlegroups.com
Hello everyone,

I am trying to do pixel perfect collision detection between rabbyt sprites but I am having some issues that I cannot figure out.
My basic attempt is to collide non-rotated sprites using axis alligned bounding boxes to find the intersection that needs to be tested. I use the following algorithm:
http://pastebin.com/dPGTk0yq
renderable and collision are dicts that contain the corresponding components. Basically collision holds the AABBs, renderable holds the sprites.

The algorithm is basically a slight modification of this version(the offset formula mostly; as using d1[1] would throw an exception because it is a string):
http://code.google.com/p/darkcoda/source/browse/sprite_collision/collide.py

Now the problem is that I get positive for collision even when the non-transparent pixels do not collide. The transparency renders correctly, I tested it, so I am fresh out of ideas of what goes wrong. I tried setting the threshold to 255 - full transparency - but  I get the same result. My only guess is that I am getting the offsets wrong somehow, but I can't figure out why or what to do to fix the problem. I have checked the AABBs and they are positioned correctly.

Note that I am not sure my approach to pixel perfect collision with rabbyt and pyglet is right (for one, I'd prefer to obtain a bitmask rather than an alpha mask, and I'd prefer it to be a 2d array rather than a 1d array). I would appreciate any advice on how to do it properly, even if it goes a totally different way

Thanks in advance!

P.S. I know how horribly slow pixel perfect collision is in pure python; I will rewrite it in pyrex or maybe even pure c as soon as I get it working.

Reply all
Reply to author
Forward
0 new messages