1
Graphics / Collision detection between sprite and shape
« on: May 03, 2021, 08:56:47 pm »
I know collision detection is most likely a topic that has been brought up here quite often, so I'm sorry for bringing it up once again.
First of all, I am not very experienced with SFML, game development and 2D graphics in general so please bear with me.
I have written a very basic game using where balls (basically an sf::CircleShape) can hit a player (basically an sf::Sprite) and while using the intersects function works just fine I would of course prefer a bit more "pixel perfect collision detection".
Instead of reinventing the wheel I have found a few snippets like this one.
I've had to change the code slightly to use an sf::Shape for one of the objects, but I cannot really see how it should matter.
The problem is, that a collision very rarely happens and for small shapes, it seems like it doesn't happen at all.
My sf::CircleShape uses a texture that scales depending on the size and I have a suspicion that when comparing the pixels, the comparison happens using the full sized image/texture where only a corner of the original image is used which mostly only contains transparent pixels. As far as I've understood though, getInverseTransform should take care of that transformation right?
Hope my question makes some kind of sense. I am of course willing to share code and more details, but I'm a bit lost so I hope someone could give my some guidance from here.
Thanks a lot!
First of all, I am not very experienced with SFML, game development and 2D graphics in general so please bear with me.
I have written a very basic game using where balls (basically an sf::CircleShape) can hit a player (basically an sf::Sprite) and while using the intersects function works just fine I would of course prefer a bit more "pixel perfect collision detection".
Instead of reinventing the wheel I have found a few snippets like this one.
I've had to change the code slightly to use an sf::Shape for one of the objects, but I cannot really see how it should matter.
The problem is, that a collision very rarely happens and for small shapes, it seems like it doesn't happen at all.
My sf::CircleShape uses a texture that scales depending on the size and I have a suspicion that when comparing the pixels, the comparison happens using the full sized image/texture where only a corner of the original image is used which mostly only contains transparent pixels. As far as I've understood though, getInverseTransform should take care of that transformation right?
Hope my question makes some kind of sense. I am of course willing to share code and more details, but I'm a bit lost so I hope someone could give my some guidance from here.
Thanks a lot!