Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 PerPixel collision handling or rectangle collision handling?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
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. –  Chris Sep 13 '11 at 10:44
2  
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). –  ashes999 Sep 13 '11 at 10:51
    
Very true! Thanks for the help! :) –  Chris Sep 13 '11 at 11:07
    
No problem. Let me know if you have specific questions about collision detection later. –  ashes999 Sep 13 '11 at 12:15
    
@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 –  Tomas Voracek Sep 16 '11 at 22:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.