2017-01-17 2 views
0

SFML 2.4.1でsf :: Textの位置を正確に設定したいのですが、フォントを設定した後、その位置は正しくありません。なぜsf :: Text型のオブジェクトが異なるgetPosition()。yとgetLocalBounds()を返すのかtop?

#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) 

どのような考えですか?

答えて

0

これは、最初の行が文字列内にない場合でも、一番高い文字の高さに垂直に配置されているために発生します。これは、最初の行に高い文字を追加しても、文字列の上端を安定させるためです。 Laurentに感謝します。

関連する問題