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.
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!
Per-Pixel Collision...
Per-Pixel Collision...
Last edited by Yojimbo on Fri Jul 23, 2010 7:57 pm, edited 1 time in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Per-Pixel Collision...
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.
Oh, and I don't think this qualifies as misuse.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Per-Pixel Collision...
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.
Re: Per-Pixel Collision...
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.
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...
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!
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Per-Pixel Collision...
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...
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Per-Pixel Collision...
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: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.
Heh. Bartbes and his... professional project naming scheme.Yojimbo wrote:Also, the explicit sexual reference will prevent me from using that library it in a graduate level course.
Help us help you: attach a .love.
Re: Per-Pixel Collision...
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.
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Per-Pixel Collision...
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#Examplespekka wrote:Whose was it again? Robin's?
Help us help you: attach a .love.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests