Per this thread, I wanted to figure out a method for pixel-perfect collision for a project I'm working on, and snaggled the in-project attempt so badly that I decided to start from scratch in a separate cart. This is the result, a little demo that shows pixel (and basic box) collision feedback in real-time on a couple of sprites.
As far as I can tell, the collision test is accurate under the assumptions this cart makes: each sprite is an 8x8 sprite referenced directly off the sprite sheet by sprite number, and any non-0 pixel is considered solid. But beyond that I am making no assumptions about it: I'm sure there are cleaner/faster/neater implementations of the same idea, and I'd encourage anyone who feels like taking a shot at cleaning it up to go for it.
This should also in principle be generalizable to arbitrary rectangles of sprite sheet info for e.g. larger multi-tile player sprites, and in fact I made some progress last night trying to generalize it, but that hasn't totally come together. Anyone who feels like tackling that, go for it.
I wrote the code to test a single pixel against any sprite out of a map. It also returns the actual sprite number and specific color. I want to use this for a platformer, so I can have sprites of any shape in my levels. Should be fun! Working out the math for this took longer than it should have, but I'm learning.
EDIT: Updated with a working .p8.png -_-
This is awesome and really interesting!
If you ever have a minute I would love to read some comments on it, would be an amazing learning moment :)
Will this work also for sprites or only for pixels?
=== Disclaimer ===
Sorry for the necroposting.
[Please log in to post a comment]