Jump to content

  • Log In with Google      Sign In   
  • Create Account


Best 2DLevel Format for Collisions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BreakBeat   Members   -  Reputation: 103

Like
0Likes
Like

Posted 05 August 2013 - 07:26 PM

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!



Sponsor:

#2 makuto   Members   -  Reputation: 832

Like
1Likes
Like

Posted 06 August 2013 - 04:11 PM

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, 06 August 2013 - 04:14 PM.

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


#3 BreakBeat   Members   -  Reputation: 103

Like
0Likes
Like

Posted 07 August 2013 - 03:29 PM

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

 

Thanks again.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS