Jump to content
  • Advertisement
Sign in to follow this  
h3ro

Collision detection for a 2d game

This topic is 3886 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

Hallo, Im wondering how to do collision detection for my simple 2D game. I get how to do it with sprite VS sprite, but not sure how to check the sprites against the actual level. I have been thinking about having a "collision image" for the level, just a black and white picture of the level to do the collision test. How is this normally handeled in a 2D game? Thanks, Ole Kristian

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by h3ro
I have been thinking about having a "collision image" for the level, just a black and white picture of the level to do the collision test.
That's one way to do it, and it will work fine if implemented correctly.

Quote:
How is this normally handeled in a 2D game?
You could:
  • Do as you already described, and keep collision data as an image (if you're not using it, you could even put this information into the alpha channel of your actual background image if you wanted to and are using a format which supports this).

  • Keep a collection of bounding boxes or other collision geometry and test for collisions against those as you would with a sprite. You'd probably want to figure out a way of dividing these up to avoid lots of unnecesary checking if your levels are very complex.

  • Store an "outline" of your level mathematically and check against those.



I'd suggest trying out the method you originally thought of yourself; it will work, and it's always a good learning exercise to try to figure these things out for yourself, so trying your own method could be good practice.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!