Best 2DLevel Format for Collisions

Started by
1 comment, last by BreakBeat 10 years, 8 months ago

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!

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.

Want to get to know my work and I better? See my website: Au 79 Games

I wrote General Tips on the Process of Solo Game Development

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

Thanks again.

This topic is closed to new replies.

Advertisement