Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Text is slightly off  (Read 1012 times)

0 Members and 1 Guest are viewing this topic.

Daniel Schreiber Mendes

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
sf::Text is slightly off
« on: September 01, 2019, 10:20:48 pm »
Hello,
I just have a sf::Text named content and want to set its position but it seems to be off about 7 Pixels vertically all the time. What am I doing wrong?
content.setPosition(0, 0);
 
std::cout << content.getPosition().x << ", " << content.getPosition().y << std::endl;
 
gives me (0, 0); thats what it should be.
But it looks like this (ignore the label ):

I am not changing its position in any way despite the first line. So where does the offset come from?
Thanks for any help!
« Last Edit: September 02, 2019, 09:27:50 am by Daniel Schreiber Mendes »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Text is slightly off
« Reply #1 on: September 02, 2019, 02:38:52 pm »
Unlike other drawables, sf::Text aligns its glyphs to its base-line, not to its top. The margin that you see is empty space that could be used by taller glyphs. You can retrieve it in text.getLocalBounds().top, and thus easily adjust the position accordingly if you need to.
Laurent Gomila - SFML developer

Daniel Schreiber Mendes

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: sf::Text is slightly off
« Reply #2 on: September 02, 2019, 03:01:07 pm »
Ah alright thanks a lot

 

anything