LaurentGomila/SFML — Issue #127: sf::Sprite.SetPosition() with float coordinates
Author: nitrix
Created: 2011-11-25 23:12:19+00:00
State: open

Explanation:
I was trying a second ago to draw a sprite (GUI button) relative to another sprite's position (GUI window). Everything worked fine except for the button to look extremely weird. I browsed the forum for explanations. Look at SetSmooth(), all anti-aliasing features, then I found the reason.

How I got the error:
1) Draw a big (sf::Sprite) centered on a sf::RenderWindow (you know the odd trick dividing the screen in half then substracting it half the size of the sprite) ...
2) Get it's position using sf::Sprite::GetPosition()
---> Notice: IF THE WINDOW SIZE ISN'T A NUMBER DIVIDABLE BY 2, YOU'LL GET FLOAT COORDINATES ENDING WITH .5
3) Draw the other sprite relative to the first one's position (that'll also give you floating .5 coordinates)
4) Observe the image distortion the new sprite is affected by... (if it's an image with text, it's clearly visible).

So I was wondering, is this sort of unconsciousness from my side (I admit I don't work with floats often) or is it a static_cast() or something wrong in the code? I think SetPosition takes 2 ints, but GetPosition returns 2 floats (my be wrong on that one tho).

Anyway, there is also some Googling I've done and I wonder if this might be the reason:
https://github.com/LaurentGomila/SFML/issues/31

Cheers.