Sign in to follow this  

Collision detection in C# via colored pixels?

This topic is 2010 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
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 ([url="http://ianqvist.blogspot.com/2010/07/broad-and-narrow-phase-collision.html"]narrow phase collision detection & broad phase collision detection[/url]). 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 [url="http://en.wikipedia.org/wiki/Quadtree"]quad tree[/url] for your broadphase collisions :)

Share this post


Link to post
Share on other sites
[quote name='slayemin' timestamp='1339416651' post='4948131']
That approach can blow up in your face if you're not careful [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] 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 ([url="http://ianqvist.blogspot.com/2010/07/broad-and-narrow-phase-collision.html"]narrow phase collision detection & broad phase collision detection[/url]). It makes no sense to do pixel vs. pixel collision detection against an object on the other side of the map [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

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 [url="http://en.wikipedia.org/wiki/Quadtree"]quad tree[/url] for your broadphase collisions [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

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?

[i]edit[/i]
What if I used the Region class and the GetBounds method? Edited by Gihzah

Share this post


Link to post
Share on other sites
Riemers has a good overview of pixel v. pixel collision detection. Here's a link to the first of three sections on it:
[url="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Coll_Detection_Overview.php"]http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Coll_Detection_Overview.php[/url]

Share this post


Link to post
Share on other sites

This topic is 2010 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this