c++ - Why object of type sf::Text returns different getPosition().y and getLocalBounds().top? -


i want precisely set position of sf::text in sfml 2.4.1, after set font, location improper.

#include <sfml/graphics.hpp> #include <iostream> #include <stdlib.h>  int main() {     sf::text text;     text.setcharactersize(24);     sf::font font;     font.loadfromfile("font.ttf"); //without loading font, everything's correct     text.setfont(font);     text.setstring("a string");     text.setposition(0, 61);     std::cout << text.getorigin().y;     std::cout << text.getposition().y;     std::cout << text.getglobalbounds().top;     std::cout << text.getlocalbounds().top;     if (text.getlocalbounds().top != text.getposition().y) return -1;     return 0; } 

i tried change origin, didn't help.

text.setorigin(0, text.getglobalbounds().height/2.f); //height correct , matches displays on screen(draw code unnecessary) 

any thoughts why?

this happens because first line aligned vertically on height of tallest character (even if it's not in string). keep top of string steady if add higher characters on first line. laurent.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -