SFML community forums

Help => General => Topic started by: denisa on December 24, 2019, 01:29:04 pm

Title: Text
Post by: denisa on December 24, 2019, 01:29:04 pm
Hello!

I'm trying to write a text on my window. This text represents the points scored by the player, which are calculated by the game algorithm. The problem is that I want to write the text during the game, not from the beginning. I want to add text constantly in that table when some buttons are pressed and I can't manage to do that. Can someone give me some ideas or something please?
Title: Re: Text
Post by: eXpl0it3r on December 24, 2019, 03:04:04 pm
You could use a std::string to hold your text, use std::to_string() to convert from numbers (your score) to text and then all you need to do is call setString on the sf::Text object.

If you haven't already, I highly recommend you read through the official tutorials (https://www.sfml-dev.org/tutorials/latest/). :)
Title: Re: Text
Post by: Tigre Pablito on December 31, 2019, 08:57:11 pm
Hi

If you want to write the text during the game, then you should draw the text object every frame, into your main loop, and you can also add a condition if you want

while (true) {

.....

text.setString(score.toString());

window.draw(text);

........

}