Displaying text in sfml

Trying to display text in sfml:

std::vector<sf::Text> npc_text(12);
if (i % 5 == 0)
        {
            dot[i] = sf::CircleShape(3);
            npc_text[i / 5].setString(std::to_string(i));
            npc_text[i / 5].setPosition(x1 + Window.getSize().x / 2, y1 + Window.getSize().y / 2);
            npc_text[i / 5].setColor(sf::Color::Black);
            npc_text[i / 5].setCharacterSize(24);
        }
while (Window.isOpen())
    {
for (auto& text : npc_text)
        {
            Window.draw(text);
        }
}

For some reason, it is not visible. What is the error?

 0
Author: Александр, 2018-01-11

1 answers

You should also download the font, and set it for the text.

sf::Font font;//Должен жить всё время, пока нужен
if (!font.loadFromFile("my_font.ttf")){
   //error
}
//...
npc_text[i / 5].setFont(font);//Внутри сохраняется указатель на объект font
 1
Author: Croessmah, 2018-01-11 16:54:53