• Advertisement
Sign in to follow this  

Best 2DLevel Format for Collisions

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

Hi,

 

I recently started using SDL and have run into a question of how to format a 2D level's collidable surfaces:

 

1) Use an image consisting of two colors; one representing walkable space, and the other filled space. I'd constantly get the color of the pixel the character(and other entities) are standing on and detect a collision if it changes color.

 

2) I use an array of rectangles(with points, widths, etc) and check every single entity against every single rectangle for a collision.

 

I'm wondering which of these methods is most efficient for the CPU and RAM. My guess is that 1) is best for CPU and 2) is best for RAM but would like elaboration. I like the idea of 1) just because I could draw up a level in PS really quick and immediately have it good to go (assuming my code is robust enough).

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

AABB collision detection is very popular. Pixel-perfect detection is also quite popular but is typically drastically slower than AABB detection.

 

With 2, you can use a quadtree or similar structures to avoid the O(n2) comparison of every object against each other.

 

1 may end up holding you back when you want to have different art/colors, but I can see some advantages (such as easy pixel-perfect destructible terrain like Worms)

 

It mostly depends on the game(s) you are planning to make; you probably shouldn't decide on one catch-all method.

Edited by makuto

Share this post


Link to post
Share on other sites

A quick search of "quadtree" gave nice results and put to rest most of my fears regarding AABB detection.

 

Thanks again.

Share this post


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

  • Advertisement