Archived

This topic is now archived and is closed to further replies.

GameDev135

re: collision detection using pixel colors in side scroller

Recommended Posts

GameDev135    133
Hey, I am writing a 2-dimensional side scroller using DirectX 8.0. For the collision detection, I am currently unable to do anything besides the simple if the 2 boxes surrounding the characters intersect, detect collision...The problem with this method is that the characters have to be drawn to completely fill the box. My question is what is a good method to use to do this? One thing I have heard is that one can read the pixel color and have the program respond accordingly... Any input would be greatly appreciated. Dan

Share this post


Link to post
Share on other sites
Pootle    122
Yes, you can test pixel colours in the sprites.

Alternatively, store a collision mask with your sprite - a simple 1 bit/pixel image, where a 1 indicates a solid part. Perform a bitwise AND operation with a second sprite''s collision mask, and any overlapping sections will give you a non-zero result.

Share this post


Link to post
Share on other sites
GameDev135    133
Ok, so if I do what you are calling a bit-pixel image, i would create another 2d array of the same dimensions as the sprite filled with 1s and 0s. Then I can test for where there are two one?

Sounds great. Now is there a quick way though to create that array from my picture as opposed to doing it manually?

Share this post


Link to post
Share on other sites
Kwizatz    1392
Ok, first keep the "bounding rectangle" colision detection, so, you first check if the rectangles intersect at all, then if they do, proceed to do the pixel perfect check, there was an article about that right here in gamedev.net right here

Cheers!

Proud aedGUI developer.

Share this post


Link to post
Share on other sites