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

Author Topic: Text  (Read 1774 times)

0 Members and 1 Guest are viewing this topic.

denisa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Text
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Text
« Reply #1 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: Text
« Reply #2 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);

........

}


 

anything