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

Author Topic: Drawing a number from a function  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

aBallofWin

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Drawing a number from a function
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Drawing a number from a function
« Reply #1 on: January 15, 2012, 02:43:35 pm »
Do you call sf::Text::SetString() every time the HP updates?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

aBallofWin

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Drawing a number from a function
« Reply #2 on: January 15, 2012, 02:50:10 pm »
sf::Text has not been declared?

Btw, how could i put this into the code?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Drawing a number from a function
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

aBallofWin

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Drawing a number from a function
« Reply #4 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

 

anything