Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Positioning Text in Window  (Read 3296 times)

0 Members and 1 Guest are viewing this topic.

djysyed

  • Newbie
  • *
  • Posts: 1
    • View Profile
Positioning Text in Window
« 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?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Positioning Text in Window
« Reply #1 on: November 06, 2020, 02:23:34 am »
You don't have any font.
Before drawing any text, you need to have an available font, just like any other program that prints text.