Log In  

Cart #11994 | 2015-07-29 | Code ▽ | Embed ▽ | No License
18

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.

P#11996 2015-07-29 12:15 ( Edited 2017-09-11 09:31)

4



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 -_-

P#12432 2015-08-07 19:09 ( Edited 2015-08-07 23:16)
1

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.

P#44087 2017-09-11 05:31 ( Edited 2017-09-11 09:32)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:49:03 | 0.010s | Q:17