XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

2D Collision Detection using a Color Map - Am I getting warmer?

Last post 1/17/2009 11:46 PM by FlyingMartini. 4 replies.
  • 1/15/2009 6:54 PM

    2D Collision Detection using a Color Map - Am I getting warmer?

    Hi, I'm currently attempting to perform 2D collision detection using a color map.

    I've searched around on google intensely trying to find something similar.  I managed to find a couple tutorials that were similar, although I can't seem to quite grasp logic.

    Here's basically what I am trying to achieve:



    This is my 'room' texture.  It's one big ugly picture.



    This is my 'map' texture.  It contains 2 colors.  Black and Magenta.  (I recently found out XNA turns magenta to an alpha.  I'm not sure if it can still be considered magenta as far as Color.Magenta goes, but for now we will assume it can be.  Otherwise I'll just change it to another color later.)

    The tutorials I have as references can be found here:

    http://www.ziggyware.com/readarticle.php?article_id=48

    http://www.xnadevelopment.com/tutorials/theroadnottaken/theroadnottaken.shtml
    http://www.berecursive.com/blog/2008/uncategorized/collision-textures-and-2drendertargets-in-xna

    The main thing I've noticed about all of these techniques is that they all use the Texture2D.GetData() method.

    Apparently it is essential... although I seem to lack the understanding to test the color against a rectangle associated with a sprite.

    This is more about obtaining the logic behind "if this rectangle touches this color, preform action X"  rather than the "preform action X" part (hope that made sense).

    Another key issue I noticed was RenderTarget2D. I can't seem to think why I personally would need to use this, although maybe I do? Who knows.

    Any help on this particular issue would be outstanding. Thank you very much.

    Oh btw, I'm kinda new to programming so be gentle ;p

    
    






  • 1/16/2009 9:16 PM In reply to

    Re: 2D Collision Detection using a Color Map - Am I getting warmer?

    With color key collision you don't test against a rectangle, you test against your sprites colors. Does a color in your sprite appear at the same location that a color from the color key appears. So in your color key image, if any color in your sprite appears in the same location as the color in your sprite, a collision has occurred. This is one of the reasons this type of collision is so expensive.

    Is there a particular part in my step by step tutorial you're finding confusing? With very little work you should be able to just place your color key and overlay into my project and have the car drive around your room. Which would then be the same as your character walking around the room if you replaced that sprite with a character sprite.


  • 1/17/2009 10:33 PM In reply to

    Re: 2D Collision Detection using a Color Map - Am I getting warmer?

    I finally got it working with my sprite.  I think what was throwing me off was that I felt like I was testing a rectangle against another sprites colors.

    I noticed you said this particular collision type is expensive.  Would there be a more efficient way of doing this?  If not, would it become a big problem down the road?

    Thanks for your post George, and also for your tutorial.  It helped me quite a bit.
  • 1/17/2009 11:13 PM In reply to

    Re: 2D Collision Detection using a Color Map - Am I getting warmer?

    Isn't there a new pixel collision sample on Shawn Hargreaves' blog? Seems like you could adopt that concept and simply test vs your color map.
  • 1/17/2009 11:46 PM In reply to

    Re: 2D Collision Detection using a Color Map - Am I getting warmer?

    That would be awesome, thx for the info MrLeebo, I'll check that out.
Page 1 of 1 (5 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG