Yes this has been discussed before, but from the hours I've spent searching I've never seen it solved. Basically, I'm trying to position a text object directly in the center of the screen, but it appears to be off by several pixels on both axels. Here is the basic code:sf::Text text;
text.setString("sf text test");
//set origin to physical center of text
text.setOrigin(text.getGlobalBounds().left + (text.getGlobalBounds().width / 2), text.getGlobalBounds().top + (text.getGlobalBounds().height / 2));
//screen is 500 * 500, so this is the center of screen
text.setPosition(250, 250);
Yet the linked image is what happens on screen. Adding 20 pixels on the x value and 4 pixels on the y value seems to account for this shift perfectly. I've concluded that this is because there is a hidden, much larger bounding box around the text that is the result of getGlobalBounds(), so how do I account for this hidden variable?
I believe there have been a lot of alterations to the text part of SFML since version 2.1 so it's likely that the latest master would solve your problem.
My SFML is a couple of months old and shows this:
(http://i.imgur.com/PNSSru1.jpg)
using the code:
sf::Font font;
font.loadFromFile("G:/Resource Pool/fonts/arial.ttf");
sf::Text text;
text.setFont(font);
text.setString("sf text test");
text.setOrigin(text.getGlobalBounds().left + round(text.getGlobalBounds().width / 2), text.getGlobalBounds().top + round(text.getGlobalBounds().height / 2));
text.setPosition(250, 250);
text.setColor(sf::Colors::Green);
In case you were wondering why there was some rounding there, it's because the text might be an odd number size and therefore will set the origin to half way between two whole number positions.
This is the difference between using round and not using it:
(http://i.imgur.com/8t2Wvxd.jpg)