I have been playing with some collision code that will operate on two images to determine a collision at the pixel level. Before I get serious, I am just wondering if anyone has already developed such a function as I am keen to reuse rather than re-invent.
I was playing with something like that but I’m Shure I was using waaaaay to much code
I was basicly checking the x and y coordinates of both than adding or subtracting for both to account for off pixels
Than probably too many if statements to check for collisions and react to them
I was hoping somebody smarter than me has done this as it is not a trivial task. Performance and compact code are always a problem with any Arduboy development.
Well that comes off a bit rude but take a peek at my github the arduel code uses something similar as the Sprite for the player is not rectangular, the collision checks at this point are only for the moving platforms as there are no enemies yet,
But like I said that should at least point you in the right direction
Which part of this is actually doing the checking?
It’s kind of hard to read.
From the way you’ve described what you’re doing it’s not what @filmote is looking for. Checking “at the pixel level” generally means looking at the sprites and comparing the individual pixels.
Firstly, I think the title might potentially be a bit confusing.
Technically speaking all sprites sort of are rectangles.
I think a better title might be something like “Optimised per-pixel collision implementation”.
Also, maybe try asking if anyone is aware of any games that appear to have this kind of collision being used. If there is a game that it has been implemented in, you don’t necissarily need the owner themselves to identify it, you just need a community of people who like playing Arduboy games and kind of know what per-pixel collision might look like. (After all, every game generally has more people playing it than writing it.)
Sorry … something I said sounds rude? Didn’t mean it too. As I said, I was hoping someone smarter than me has done it and if you have then you, my friend, are smarter than me! (Which isn’t hard!) I will have a look at your code, Thanks.
Yeah that might have been better, or confused people more!
For a bouncing ball, I am checking some boundary points with
getPixel function before drawing the ball itself:
This is a lousy solution but you probably can do something similar if you want to use the screen buffer directly for non rectangular collisions
Thanks @eried for the feedback. I have a number of different shapes that I want to compare and unfortunately they are not as regular as a ball!