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

Pixel Perfect Collision Detection

Started by amigagamedev Aug 9, 2005 at 8:32 AM 4 replies 1.3k views
Original Post
amigagamedev
amigagamedev
I need to do a Perfect Pixel Collision Detection Using Directx 9 Direct3d Sprite class for a 2d game. I'm using Visual Basic .net Anyone can help me? Sample code? Thank you
centipede
centipede
You could store additional "collision maps" of your sprites in system memory (do not use them as textures!). They could be just simple black-and-white images with black indicating "hard" pixel and white empty space. Notice that you have to rotate and move them so they're always at the same position as the sprite. Then you could just test collisions between these.
k0ns0l3
k0ns0l3
What I do is something like AP said before me... You calculate how much the boxes overlap and then for each pixel in that "overlap box" you see if theres a collision. Now, for the alpha mask I would advise that the enemy masks should only be rotated if they're close enough to the player, to have in fact the possibility of collision, since that kind of operation tends to be costy... You could do that by defining sectors in the screen, quadtrees or simple bounding circle collisions.
After you checked for collisions and rotated the sprite you could have a flag that indicated that the mask was already rotated, if you would need to use it again for some purpose, like enemy-enemy collision. This also assumes you check for collisions AFTER you have updated the enemy, since you should always put the flag off in the updating process....
amigagamedev
amigagamedev
How can calculate the overlap boxe?
I try to use the intersectrect but whitout result


Can anyone write a simple sample code?

Thank you
Corsix
Corsix
You might want to consider bounding polygon collision, as it would be quicker processor wise and about 90% as accurate if compared to pixel perfect.

Topic Locked

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

Sign in to reply to this topic.