Pixel-Perfect Collision Demo

Publicado 2023-06-12


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.