SFML community forums

Help => Graphics => Topic started by: benwang08 on July 01, 2021, 12:07:17 am

Title: Basic sprite questions
Post by: benwang08 on July 01, 2021, 12:07:17 am
I have a few basic sprite questions i'm a bit new to SFML.

So i want to display some kind of sprite and also be able to detect collisions, this sprite is a sort of abstract shape, with a transparent background in a rectangular png file.

so what would be the best way to go about this, i'm aware of several, I think its possible to just load the sprite into a sprite class, but my question is, would the transparent background be apart of the sprite still? for example, if something collided with the transparent background would that register as a collision to the sprite?

And i've found another way to roughly approximate the sprite with a convex shape, than load the sprite as a texture into that shape, but i was just wondering if this was necessary.
Title: Re: Basic sprite questions
Post by: eXpl0it3r on July 06, 2021, 06:51:19 pm
An SFML sprite just gives you an axis-aligned bounding box via getGlobalBounds() and it will match the texture/texture rect.

What is often done is to decompose the sprite shape into a bunch of smaller rectangles and use that as an approximation to your shape while still keeping the math kind of manageable.
This also allows you to for example pick a smaller bounding box around "hair" or other things you don't want to directly cause a collision, so you can fine tune the experience for the player.