【问题标题】:Font in SFML. Information is not displayed on the screen. Instead of information, a dot is displayedSFML 中的字体。信息不显示在屏幕上。显示的不是信息,而是一个点
【发布时间】:2020-04-25 23:54:20
【问题描述】:

SFML 中的字体。信息不显示在屏幕上。代替信息,显示一个点。我同时输出了文本和数值,但点仍然显示。

下面这部分的代码有错误或错误编写:

    sf::RenderWindow area(sf::VideoMode(960, 540), "Prog", sf::Style::Close | sf::Style::Titlebar);

    sf::Font font;
    font.loadFromFile("Font/golos_text.ttf");

    char count[10];
    _itoa_s(this->saves->getMoney(), count, 10, 10); // Should turn (int) 20 into (char *) "20"

    sf::Text text(count, font, 20);
    text.setFillColor(sf::Color::Black);
    text.setStyle(sf::Text::Bold);

    text.setString(count); // [1] If you print (int) count - a POINT is displayed at the coordinates 20x20
    /* text.setString("HALLO"); */ // [2] If you print char* "HALLO" - a POINT is displayed at the coordinates 20x20

    text.setPosition(20, 20);
    area.draw(text);
    area.display();

【问题讨论】:

  • 显而易见的问题:loadFromFile 是否返回true,这个golos_text 字体是什么字体?它是 TrueType 还是 Bitmap 字体?如果是后者,是否支持字符大小 20?

标签: c++ c sfml display


【解决方案1】:

您似乎只是忘记将字体应用于text

text.setFont(font);

SFML 不提供默认字体,所以这是至关重要的一步

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2022-09-28
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    相关资源
    最近更新 更多