Log In  
Log In  

Cart [#11994#] | 2015-07-29 | No License | Embed

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)


Cart [#12433#] | 2015-08-07 | License: CC4-BY-NC-SA | Embed

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)
:: ltpitt

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]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-12-12 16:58 | 0.026s | 4194k | Q:29