"Pixel-Perfect" Collisions...

Started by
4 comments, last by Orymus3 10 years, 6 months ago

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!

Advertisement

Allegro - Pixel Perfect Collisions

--"I'm not at home right now, but" = lights on, but no ones home

I started off with these tutorials, for C#/XNA:

MSDN

Color Key

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)

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

Forgot to mention, this needs to work with Dart.

Luckily, I have StageXL.

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

Thanks!

This topic is closed to new replies.

Advertisement