6
\$\begingroup\$

I'm writing a platformer engine with XNA and was wondering what method for handling collisions I should use. Would I be seeing some performance issues if I were to try and have PerPixel collisions? Should I be using per pixel collision handling or rectangle collision handling?

\$\endgroup\$
4
\$\begingroup\$

In general, per pixel collision detection is much more expensive; so as much as possible, use rectangle collision handling. (Even for per-pixel, use rectangles first to check for overlap.) When I implemented collision detection in Radiant Wrench, this is precisely what I used.

Alternatively, you can try Flat Red Ball (which I used to use before), which uses polygons for detection (which is quite performant). You can use basic types (rectangle/circle) or create your own polygon from verticies. They don't support per-pixel collisions though.

\$\endgroup\$
5
  • \$\begingroup\$ Hmmm, yes I see... Would the performance still be an issue if I used rectangles first to check for an overlap? I'm thinking maybe I will only use per pixel collision for things like attacks and maybe enemies. \$\endgroup\$
    – Chris
    Sep 13 '11 at 10:44
  • 2
    \$\begingroup\$ The golden rule of performance is "don't worry about performance until you see a bottleneck happen." You have to use rectangles first, there's no real alternative. Rectangle bounds checking is very very trivial (because it doesn't support rotation). \$\endgroup\$
    – ashes999
    Sep 13 '11 at 10:51
  • \$\begingroup\$ No problem. Let me know if you have specific questions about collision detection later. \$\endgroup\$
    – ashes999
    Sep 13 '11 at 12:15
  • \$\begingroup\$ @ashes999 "don't worry about performance until you see a bottleneck happen." - and thats the reason why there is so much of unoptimized software when hardware is so cheap right \$\endgroup\$ Sep 16 '11 at 22:30
  • \$\begingroup\$ @Tomas right. Hardware scales easily. Also, this is why we have so much slow software -- it was "optimized" by someone who didn't know the first thing about optimization. \$\endgroup\$
    – ashes999
    Sep 17 '11 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .