Per-Pixel Collision...

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Yojimbo
Prole
Posts: 6
Joined: Wed Jul 21, 2010 2:25 pm
Location: Dallas, TX
Contact:

Per-Pixel Collision...

Post 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!
Last edited by Yojimbo on Fri Jul 23, 2010 7:57 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Per-Pixel Collision...

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Per-Pixel Collision...

Post 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 “^^”.
Help us help you: attach a .love.
User avatar
Yojimbo
Prole
Posts: 6
Joined: Wed Jul 21, 2010 2:25 pm
Location: Dallas, TX
Contact:

Re: Per-Pixel Collision...

Post 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.
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: Per-Pixel Collision...

Post 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!
Good bye.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Per-Pixel Collision...

Post 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.
User avatar
Yojimbo
Prole
Posts: 6
Joined: Wed Jul 21, 2010 2:25 pm
Location: Dallas, TX
Contact:

Re: Per-Pixel Collision...

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Per-Pixel Collision...

Post 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.
Help us help you: attach a .love.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Per-Pixel Collision...

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Per-Pixel Collision...

Post 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
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 74 guests