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

Author Topic: HITBOX FloatRect  (Read 2068 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
HITBOX FloatRect
« on: June 10, 2022, 09:27:14 am »
Hello, i need a Hitbox for my player that is smaller than the Player Sprite Rect. I read that the FloatRect can do it, but theres is no getglbslBounds for it, can someonr give me an advise, how i can use a floatrect with globalbounds for my player sprite?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: HITBOX FloatRect
« Reply #1 on: June 10, 2022, 09:30:26 am »
You can get the global bounds of your sprite and then reduce the size of the rect slightly to fit your needs as hitbox.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: HITBOX FloatRect
« Reply #2 on: June 10, 2022, 09:42:09 am »
How i reduce a sprite rect, there is no setSize function for it?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: HITBOX FloatRect
« Reply #3 on: June 10, 2022, 10:09:33 am »
You modify the rect returned by getGlobalBounds, not the sprite itself.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: HITBOX FloatRect
« Reply #4 on: June 10, 2022, 11:42:04 am »
I have no idea yet how to modify a rect returned by globalbounds, is there any example out in the web?

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: HITBOX FloatRect
« Reply #5 on: June 10, 2022, 12:21:35 pm »
Okay i find solution:
FloatRect playerHitbox = PlayerSprite.getGlobalBounds();
 
 if(playerHitbox.intersects(EnemySprite.getGlobalBounds())){

 

How i can set the size for playerHitbox?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: HITBOX FloatRect
« Reply #6 on: June 10, 2022, 01:48:40 pm »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/