我想在SFML 2.4.1中精确设置sf :: Text的位置,但在设置字体后,其位置不合适。
#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 any 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;
}
我试图改变原点,但它没有帮助。
text.setOrigin(0, text.getGlobalBounds().height/2.f); //height is correct and it matches with what displays on the screen(draw code is unnecessary)
有什么想法?