Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Basic sprite questions  (Read 4032 times)

0 Members and 1 Guest are viewing this topic.

benwang08

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Basic sprite questions
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Basic sprite questions
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything