SFML community forums

Help => Graphics => Topic started by: aBallofWin on January 15, 2012, 02:27:32 pm

Title: Drawing a number from a function
Post by: aBallofWin on January 15, 2012, 02:27:32 pm
I'm currently coding a battle system, and I'm having a little trouble with displaying a number from a function.

What I need to do is display the hero's and enemy's hp, and to get the enemy's hp, i have a function that in a text based environment I used to call with:

cout << enemy.GetHP();

But I'm not to sure how to keep the number updated on the screen. I tried

    sf::String anyText;

    std::stringstream enemyhp;
    enemyhp << enemy.GetHP();
    anyText.SetText(enemyhp.str());

    anyText.SetFont(Font);
      anyText.SetSize(30);
      anyText.SetColor(sf::Color::Black);
      anyText.SetPosition(20.f,100.f);

and drew it on the screen, but it doesn't update :( anyone know how i could do this?


Cheers,

Jake
Title: Drawing a number from a function
Post by: Nexus on January 15, 2012, 02:43:35 pm
Do you call sf::Text::SetString() every time the HP updates?
Title: Drawing a number from a function
Post by: aBallofWin on January 15, 2012, 02:50:10 pm
sf::Text has not been declared?

Btw, how could i put this into the code?
Title: Drawing a number from a function
Post by: Nexus on January 15, 2012, 02:57:07 pm
In SFML 1.6, it's sf::String. But you didn't write sf::Text::SetString() exactly like this in the code, did you?

Anyway, I meant that you should call the SetText() function every time the HP are updated, not just once.
Title: Drawing a number from a function
Post by: aBallofWin on January 15, 2012, 03:03:45 pm
Yeah, did some research and sf::Text is in sfml2, not 1.6, going to do some experimenting for a bit, cheers