• Advertisement
Sign in to follow this  

"Pixel-Perfect" Collisions...

This topic is 1591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement

What kind of game? I don't know of any tutorials, but for collision detection, 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

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

Forgot to mention, this needs to work with Dart.

Luckily, I have StageXL.

Thus, tutorials are ideal (I'll use Haps' as ref)

 

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement