sf::Sprite s(playerSpriteSheet, sf::IntRect(1, 1, 7, 6));
s.setScale(9.0f, 9.0f);
s.setOrigin(s.getLocalBounds().width / 2, s.getLocalBounds().height / 2);
s.setPosition(400.0f, 50.0f);
s.setRotation(180.0f);
I'm initializing a sprite with the above code. If I was to then find the value for the top of the global bounds I should get 23 and here's how: Since the scale of the sprite is 9 the height would be 6 x 9 or 54. The origin of the sprite is in the very center so the center of the sprite globally is 400, 50. To get the top of the global bounds you'd subtract half of the height from 50: 50 - 54 / 2 = 23. So when I call
s.getGlobalBounds().top I should get 23 but I actually get 22.9999962 and when I call
s.getGlobalBounds().height I should get 54 but instead I get 54.0000038.
I'm aware that since the sprite is rotated 180 degrees some floating point arithmetic is involved and thus gives me incorrect numbers because of the inherit problems with floating point arithmetic. But what if I was to tell you that the incorrect value are only present when the position of the sprite on the y axis is less than 92? When I set the y position of the sprite to 92 the correct values are returned, but when I set the y position of the sprite to 91, I then get values that are slightly off like mentioned above.
It's so strange to me that the values are only incorrect when the sprite's y position is less than 92. Why is this the case and is there anything I can do to ensure I'll always get the correct values regardless of the sprites position?