Page 1 of 3

Per-Pixel Collision...

Posted: Fri Jul 23, 2010 7:30 pm
by Yojimbo
For those of you who are interested, I’ve written a LOVE sample that demonstrates how to perform per pixel collision between two PNG images. It basically examines the PNG image’s transparent pixels and creates a collision map which can be used later to test for the collision of two non-transparent pixels. It’s definitely slower than doing a basic bounding box collision check but necessary if you want to check something like an image of the player’s ship against a much larger image of some terrain.

If I’ve misused the LOVE engine/framework in any way please let me know. I’m evaluating LOVE for use in a university course and I’m very interested in writing samples and demos that use it correctly.

Image

I tried uploading the file via the forum but it garbles it on download, so here's a plain 'ol link:
You may have to do a right-click and "Save As Link..." to get it.

http://www.codesampler.com/source/love_ ... ision.love

Enjoy!

Re: Per-Pixel Collision...

Posted: Fri Jul 23, 2010 7:56 pm
by bartbes
Only the name garbles on forum uploads, and I keep telling thelinx to fix it (see?).
Oh, and I don't think this qualifies as misuse.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 12:13 am
by Robin
In any case of actual misuse (or abuse, even), the five knolls at the top of the forum pages will cry instead of do “^^”.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 4:32 am
by Yojimbo
Well, I guess I should clarify what I mean by "misuse". What I mean is , if I'm not using LOVE in the best possible way or if I'm implementing something which LOVE can already do, but I'm unaware of, please let me know.

While I'm on the subject, am I correct in my understanding that LOVE no longer supports an animated image loader in 0.6.2? Older samples seem to make use of a newAnimation() function to load image files that contains multiple sub-images.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 5:31 am
by Luiji
Knolls? Well, now I understand where the IRC bot's name comes from!

Pixel perfect collision is cool! Currently to get such functionality you need to use the heavy love.physics library, so this will be great!

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 8:06 am
by bartbes
Correct, in 0.6.0 animations were removed, in order to provide legacy support I created a replacement library mimicing the API, it's called Animations And Love (AnAL), it has its own wiki page.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 3:21 pm
by Yojimbo
I guess there was a reason for its removal, but removing animation support seems like going backwards since animated sprites are such a basic concept in 2D engines. Also, the explicit sexual reference will prevent me from using that library it in a graduate level course. I'll just have to roll my own and add it directly to the course's starter game. Not a huge deal.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 3:29 pm
by Robin
Yojimbo wrote:I guess there was a reason for its removal, but removing animation support seems like going backwards since animated sprites are such a basic concept in 2D engines.
Well, animations are actually much more powerful in 0.6.* than before. They are not called Animations anymore, but Quads, because they can do much more than animating.
Yojimbo wrote:Also, the explicit sexual reference will prevent me from using that library it in a graduate level course.
Heh. Bartbes and his... professional project naming scheme.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 3:38 pm
by pekka
Your image named terrain.png has extents that are not powers of two. This means it won't display properly for some people. It is considered good manners to use images that have power of two extents, because of this limitation stemming from the capabilities of some graphics cards. There's also a helpful tool around here somewhere that will pad your images automatically. Whose was it again? Robin's?

As a clarification, the x and y sizes need not be the same, both just have to be some power of two. And the issue affects only some computers, cards and driver versions. It comes down to whether the particular OpenGL implementation supports non-POT textures or not.

Re: Per-Pixel Collision...

Posted: Sat Jul 24, 2010 7:11 pm
by Robin
pekka wrote:Whose was it again? Robin's?
Not completely, it wasn't my idea or original code, but I did make the unlove script (for Linux/UNIX) and turned padding.lua in its current form. It is based on this: http://love2d.org/wiki/ImageData#Examples