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

Author Topic: Text  (Read 721 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 2
    • View Profile
« on: December 24, 2019, 01:29:04 pm »

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?


  • SFML Team
  • Hero Member
  • *****
  • Posts: 10044
    • 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
Nightly Builds: https://www.nightlybuilds.ch/
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Tigre Pablito

  • Full Member
  • ***
  • Posts: 219
    • View Profile
    • Email
Re: Text
« Reply #2 on: December 31, 2019, 08:57:11 pm »

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) {