Search code examples
c++sfml

Is there a way to detect the pixels of a sprite for a collision in SFML?


It doesn't have to be pixel-perfect collision, but I want it to be as close as possible to the actual pixels of the sprite. FYI, I created a 32 by 32 sprite but then I was only able to fill estimately half the amount of pixels, so the rest is just transparent.


Solution

  • Most games out there don't use anything close to pixel perfect collision and it's usually not needed. Having some approximated rectangle or a combination of multiple rectangles is usually enough.

    SFML itself provides intersects() and contains() functions for it's sf::Rect<T> class.

    There's also some collision detection class in the SFML wiki which also features a bit-mask collision, that's basically a pixel-perfect collision detection.