🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

2D Colission, any thoughts?

Started by
1 comment, last by GameDev.net 24 years, 7 months ago
My first thought would be to use the bounding box as an initial test, then, if the bounding boxes intersect, use some more expensive operation to figure out whether the objects really do intersect or whether it was a false alarm. Most of the time a circle centered on some point of a sprite does a good job assuming the sprite bounding box is close to square.

- Splat

Advertisement
Mmm I'm just curious about the fastest and best looking way of detecting a collision between 2d objects(eg. sprites).

I know that you could simply test if the 2 bitmaps(and by this I mean squares with irregular "figures" in them) are overlapping each other.
But that won't look so good..
Maybe one could put many rectangels in each bitmap and test all of them... that would look better...

But is there not a better way of doing this?
Maybe check every pixel? This doesn't sound that fast though..

Hmm any thoughts? How do "real" programmers do in public games?

comments: I'm using DirectX 7.0 and C++. Blitting the sprites to the screen.. Perhaps there is a built in function in the blitter ior Dx?
Mmm and well I would be very happy for some code too

Thanks!

Basically, you first check if your sprite cant potentially collide, just by testing the boxes containing the sprites. If the boxes collide, then you can use a pixel collision detection, using the mask of your sprites.

Not clear ? Example ->

Suppose you have a 32x32 sprite.
You can build an array of 32 DWORD, each dword containing the mask for one line of ur sprite. (Bit 31 = 1 if pixel 0 not color key, etc ... ) Ok ?

No supposing you have 2 representations of this sprites, S1 at (X1,Y) , S2 at (X2,Y)
and X2-X1<32 (so the boxes collide !)

we set DX=X2-X1;
then for each row of the sprites :
{
A = MASK_S1[ROW] & (MASK_S2[ROW]<< DX)
if (A != null) then collide

}

This is just what i do to test my sprite collision, and it works fine
Doing it in ASM is easy, and you can modify the algo to work with sprites >32 pixels width...


Hope it helps you ..

Tchaoo.......Zargoun!

[This message has been edited by Zargoun (edited November 10, 1999).]

This topic is closed to new replies.

Advertisement