为什么类型为 sf::Text 的对象返回不同的 getPosition().y 和 getLocalBounds().
Why object of type sf::Text returns different getPosition().y and getLocalBounds().top?
我想在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)
有什么想法吗?
发生这种情况是因为第一行垂直对齐在最高字符的高度上(即使它不在字符串中)。这是为了保持字符串顶部稳定,即使您在第一行添加更高的字符。感谢洛朗。
相关文章:
- Cpp-Tuple使用带有变量的get
- 通过 get-Method 访问变量在类外不起作用
- 为什么无论你输入什么,这"while(cin.get(str,3))"只运行一次?
- Boost.Asio/OpenSSL HTTPS GET certificate trouble
- C++中是否有任何函数等同于python中字典的get函数?
- 使用istringstearm和get行缓慢读取文件
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 使用 cin.get() 初始化字符数组
- std::variant<>::get() 不能使用 Apple LLVM 10.0 编译
- 编写 cin.get() 以接收字符数组时出现问题
- 作用域枚举和标准::get
- Visual Studio 2017 中的 cpprestapi 问题找不到 POST/GET 常量
- 在 C++/C 中使用 CURL 发出带有数据文件的 GET HTTP 请求
- 使用"push_back"作为带有"get"函数C++的向量
- 使用 cin.get 读取字符数组
- 如何使用 fstream 的 .get 字符串?
- std::get like (partial) template specialization
- 从 unique_ptr::get 发送指针作为指针引用进入函数
- addr2line get 行号始终返回 0
- unique_ptr<T>::get() 返回的指针在原始unique_ptr被销毁后不是 nullptr