I am making a game where you fly a ship around some randomly generated planets. Since I am using a for loop to draw over 5000 planets, using the rectangle class or an oval-type class for this is not an option, since creating many objects will severely affect performance. Bitmasking each planet will likely result in performance issues too, so the only candidate is color based collision detection, because I don't need to apply some sort of object to everything I want to check for collisions. Is any way to check the perimeter around the ship for a certain color?
|
|
Color based checking is really slow. It is used rarely these days, and only for some specific problems like when using deformable terrain. Probably a better approach is to minimize number of comparisons. I suggest you organize your planets in a quadtree first. Trees will quickly limit number of comparisons, because if you know that a planet fits in one quadrant, you immediately know it cannot intersect any planets in other 3 quadrants thus reducing your search space by 75% with a single comparison. After this, you should do rough collision testing using rectangles because these are quick tests, much faster then circle or oval. Only if the hit is probable, then you do a thorough check, maybe even color or bitmask if you have to. But then the number of comparisons is really low because you have eliminated great many planets by this time. This problem is basic scene management, and you will be well advised to use a 3rd party library rather then inventing your own. |
|||||||
|
