【发布时间】:2014-01-11 16:54:59
【问题描述】:
最近我遇到了一个问题。我无法让 sf::Text 工作。不知道为什么,字体似乎正在加载。 代码如下:
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");
sf::Font font;
sf::Text text;
if(!font.loadFromFile("/usr/share/fonts/TTF/arial.ttf"))
std::cout<<"Error";
text.setFont(font);
text.setCharacterSize(30);
text.setColor(sf::Color::Blue);
// Start the game loop
while (app.isOpen())
{
// Clear screen
app.clear();
// Draw the sprite
app.draw(text);
// Update the window
app.display();
}
return 0;
}
有什么建议吗?
【问题讨论】:
-
对 SFML 一无所知,但您是否真的在某处为
text设置了文本?我只看到字体和颜色。 -
在游戏循环之前尝试
text.setString("Hello World"); -
啊,我太笨了。很抱歉浪费您的时间xD