• Advertisement
Sign in to follow this  

Collision detection in C# via colored pixels?

This topic is 2079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying to come up with a way to add collision to the scenery in my game without the use of a level editor. The best thing I could come up with is using an overlay image who's alpha value would be set to 0 and would contain pink pixels outlining the collision on the level - After which, I'd use pointF to draw the collision lines. I'm just not sure how I'd go about telling C# to detect the pink pixels and to put a point on them. Has anyone ever taken this approach? Is it even practical and or possible?

Share this post


Link to post
Share on other sites
Advertisement
My understanding is, it's even common, although not completely accurate, due to the possibility of something moving fast enough it just jumps past the other object.

Share this post


Link to post
Share on other sites
That approach can blow up in your face if you're not careful :P You'll want to use the pixel vs. pixel comparison in a "granular" collision detection routine since its expensive and use a coarser method for general collision detection (narrow phase collision detection & broad phase collision detection). It makes no sense to do pixel vs. pixel collision detection against an object on the other side of the map :)

I just use bounding boxes or bounding spheres for my broad phase collision detection and the narrow phase uses a slightly more expensive "polygon" collision detection method (the graphic is enclosed within a polygon). I chose the polygon because its easy to rotate and transform.

Alternatively, you could use a quad tree for your broadphase collisions :)

Share this post


Link to post
Share on other sites

That approach can blow up in your face if you're not careful tongue.png You'll want to use the pixel vs. pixel comparison in a "granular" collision detection routine since its expensive and use a coarser method for general collision detection (narrow phase collision detection & broad phase collision detection). It makes no sense to do pixel vs. pixel collision detection against an object on the other side of the map smile.png

I just use bounding boxes or bounding spheres for my broad phase collision detection and the narrow phase uses a slightly more expensive "polygon" collision detection method (the graphic is enclosed within a polygon). I chose the polygon because its easy to rotate and transform.

Alternatively, you could use a quad tree for your broadphase collisions smile.png


Thanks! This approach makes much more since. I've never worked on anything like this before so I'll have to do some messing around with it. Would you happen to know how I would go about using pixel vs pixel comparison in c#? And would I have to use bitmap images?

edit
What if I used the Region class and the GetBounds method? Edited by Gihzah

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement