SFML Collision Detection

Just curious which type of collision detection would you recommend in sfml game programming out of: Distance Based, Bounding Box, Pixel perfect?
Why not use multiple collision detection methods?

I believe SFML comes with built-in collision detection using sf::FloatRect, I believe the methods are called "intersects" and "contains".
closed account (o1vk4iN6)
Generally there is some sort of broad-phase which is a simplification of complex objects, generally axis aligned bounding box is used (sphere's can be used as well and doesn't require rotation). So if you want pixel perfect you would give your sprites a bounding box and put them in some sort of spacial partitioning to only test them in the same area. This really depends on the scope though, if you only plan to have 100 objects, you can probably get away with just using bounding boxes without hitting a performance wall.
Last edited on
closed account (3qX21hU5)
SFML gives a example of collision detection on the github page https://github.com/LaurentGomila/SFML/wiki/Source%3A-Simple-Collision-Detection-for-SFML-2 .

It includes BoundingBox BoundingCircle and PixelPerfect collision tests. You could probably adapt this into your game and improve upon it. There really isn't a one size fits all for collision detection when it comes to games. Use what works best for you.
Topic archived. No new replies allowed.