SFML community forums

Help => Window => Topic started by: djysyed on November 06, 2020, 01:47:05 am

Title: Positioning Text in Window
Post by: djysyed on November 06, 2020, 01:47:05 am
Hey all,

I am relatively new to SFML (3 days new to be precise) and am trying to figure out how to show the amount of time that has passed. At the moment my function for doing so is:

void Game::DisplayGameTime() {
    sf::Text game_time;
    game_time.setString(std::to_string(game_clock.getElapsedTime().asSeconds()));
    game_time.setCharacterSize(100);
    game_time.setFillColor(sf::Color::White);
    game_time.setPosition(0.f, 0.f);
    my_window.draw(game_time);
}
 

I've been messing around with CharacterSize and setPosition but none of the 10 different values have produced any visible text. The code for how I'm using this function is:

void Game::Render() {
    my_window.clear();
    for (int i = 0; i < NUMSPRITES; i++) {
        my_window.draw(sprites[i]);
    }
    DisplayGameTime();
    my_window.display();
}
 

Any tips or pointers (no pun intended) in the right direction?
Title: Re: Positioning Text in Window
Post by: G. on November 06, 2020, 02:23:34 am
You don't have any font.
Quote from: https://www.sfml-dev.org/tutorials/2.5/graphics-text.php
Before drawing any text, you need to have an available font, just like any other program that prints text.