Sign in to follow this  
44cll

Collision detection in C# via colored pixels?

Recommended Posts

44cll    134
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
slayemin    6089
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
44cll    134
[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
Khaiy    2148
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

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