SFML community forums

Help => Graphics => Topic started by: Jan666 on June 10, 2022, 09:27:14 am

Title: HITBOX FloatRect
Post by: Jan666 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?
Title: Re: HITBOX FloatRect
Post by: eXpl0it3r 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.
Title: Re: HITBOX FloatRect
Post by: Jan666 on June 10, 2022, 09:42:09 am
How i reduce a sprite rect, there is no setSize function for it?
Title: Re: HITBOX FloatRect
Post by: eXpl0it3r on June 10, 2022, 10:09:33 am
You modify the rect returned by getGlobalBounds, not the sprite itself.
Title: Re: HITBOX FloatRect
Post by: Jan666 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?
Title: Re: HITBOX FloatRect
Post by: Jan666 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?
Title: Re: HITBOX FloatRect
Post by: eXpl0it3r on June 10, 2022, 01:48:40 pm
Checkout the documentation: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Rect.php