title: SFML Drawing centered text
body: <p>I'm trying to center some text in SFML. It doesen't really work though as you can see in the picture below.
  <img src="https://i.stack.imgur.com/RmFU9.png" alt="enter image description here"></p>
  
  <p>Maybe something is wrong with my math?</p>
  
  <pre><code>void TextRenderer::renderCentered(sf::RenderWindow&amp; window, std::string string, sf::Vector2f     position, int size, sf::Color color) {
      sf::Text text;
  
      text.setFont(TextRenderer::kavoon);
      text.setString(string);
  
      float width = text.getLocalBounds().width;
  
      text.setPosition(position.x - width / 2, position.y);
  
      text.setCharacterSize(size);
      text.setColor(color);
  
      window.draw(text);
  }
  </code></pre>
  
  <p>in render method:</p>
  
  <pre><code>TextRenderer::renderCentered(*window, pickuptext.str(), sf::Vector2f(player-&gt;sprite.getPosition().x, player-&gt;sprite.getPosition().y - 48), 28, sf::Color(255, 145, 61));
  TextRenderer::renderCentered(*window, pickuptextdesc.str(), sf::Vector2f(player-&gt;sprite.getPosition().x, player-&gt;sprite.getPosition().y - 16), 18, sf::Color(255, 145, 61));
  </code></pre>