Per-Pixel / Pixel Perfect collision yay or nay?
Posted: Thu Mar 02, 2017 1:12 am
Hey there! I've decided to take the plunge and start coding using Love2D
All my previous experience coding games has been in scratch - but I've made some pretty good stuff
I want to try converting one of my games into Lua and into a Love2D format - so far so good. I have the basics of my character down - he runs, he jumps etc.
However I'm struggling with the hit detection, scratch can check when two sprites are overlapping, but love2D requires hitboxes/bounding boxes around any objects you want to collide, however, I've come across Per-Pixel / pixel perfect collision on these forums, however most of the posts are several years old, or all the replies are negative saying it shouldn't be done - most say they should use bounding boxes on their objects and work out collisions using that - however this seems like it would take forever if I have several sprites like this: One of my 100 "ground" sprites
Not to mention, I remember reading you can only make 8 sided polygons for detection, which would mean making several hitboxes for a single sprite. So what do I do? I'm aware of the getPixel function and that maybe I could use the none-alpha pixels to create a sort of perfect bounding box but is this the best way? Is this a horrible endeavor? Should I be doing something else?
TL;DR: In Scratch there's an "if touching" block for when two objects are overlapping - I use this and apply my code to separate the sprites - is there a way to create a pixel perfect hitbox around my "ground sprites" and check for collisions on a bounding box. Do you recommend a specific library for this, or is there a better way entirely.
All my previous experience coding games has been in scratch - but I've made some pretty good stuff
I want to try converting one of my games into Lua and into a Love2D format - so far so good. I have the basics of my character down - he runs, he jumps etc.
However I'm struggling with the hit detection, scratch can check when two sprites are overlapping, but love2D requires hitboxes/bounding boxes around any objects you want to collide, however, I've come across Per-Pixel / pixel perfect collision on these forums, however most of the posts are several years old, or all the replies are negative saying it shouldn't be done - most say they should use bounding boxes on their objects and work out collisions using that - however this seems like it would take forever if I have several sprites like this: One of my 100 "ground" sprites
Not to mention, I remember reading you can only make 8 sided polygons for detection, which would mean making several hitboxes for a single sprite. So what do I do? I'm aware of the getPixel function and that maybe I could use the none-alpha pixels to create a sort of perfect bounding box but is this the best way? Is this a horrible endeavor? Should I be doing something else?
TL;DR: In Scratch there's an "if touching" block for when two objects are overlapping - I use this and apply my code to separate the sprites - is there a way to create a pixel perfect hitbox around my "ground sprites" and check for collisions on a bounding box. Do you recommend a specific library for this, or is there a better way entirely.