Sign in to follow this  
Orymus3

"Pixel-Perfect" Collisions...

Recommended Posts

Orymus3    18821

Hi,

 

I've been working on a number of games/prototypes up to now, but I've always been doing my 2D collision checks using rectangles up to now.

I was wondering if there were any tutorials or articles that you knew would be good for me to start on 'pixel-perfect' collisions as this is something I've never done before.

 

Thanks!

Share this post


Link to post
Share on other sites
DekuTree64    1168

What kind of game? I don't know of any tutorials, but for collision [i]detection[/i], it should be pretty straightforward. I'd do it with bitmasks, where each bit corresponds to one pixel of the sprite (1 for solid, 0 for non-solid). Then bitshift according to the sprites' relative X positions, AND together, and if the result is zero, no collision. Nonzero means one or more pixels overlapping. If you limit your sprites to 32 pixels wide, the collision mask can just be an array of 32-bit unsigned longs, one for each row of pixels in the sprite.

 

But I'd only use it for detection of collisions with bullets or other attacks, not for anything motion related. Motion is hard enough with geometric shapes, and pixel perfect might not behave well even if you did get it working (snagging pixels of the character on ledges and such)

Share this post


Link to post
Share on other sites
Makers_F    936

https://github.com/MakersF/CollisionCore

This library implements pixel perfect collision detection for sprite, supporting every affine transformation (translation, rotation, skew, scale)

You need to implement IBitmap as an adapter for your image, and use it to generete the pixelperfectmask.

Once you have the pixel perfect mask, you can check if they collide by passing them and the transformation of the sprites.

If you use java, in javabingind you already find an implementation for IBitmap for adapting BufferedImage

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this