Skip to main content
GameDev.net gamedev.net
🔒 Locked

"Pixel-Perfect" Collisions...

Started by Orymus3 Oct 18, 2013 at 4:35 AM 4 replies 2.7k views
Original Post
Orymus3
Orymus3

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!

Haps
Haps

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

MSDN

Color Key

DekuTree64
DekuTree64

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)

Makers_F
Makers_F

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

Orymus3
Orymus3

Forgot to mention, this needs to work with Dart.

Luckily, I have StageXL.

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

Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.