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

Author Topic: Draw fps with window.draw  (Read 2038 times)

0 Members and 1 Guest are viewing this topic.

angdrw

  • Newbie
  • *
  • Posts: 2
    • View Profile
Draw fps with window.draw
« on: March 11, 2016, 08:53:25 pm »
Hey i come up to a problem and i have no idea how to fix it, The problem is that i want to draw fps on the screen and it does so. But it seems that i does that multiple times . I think i have to reset the text.setString, It look like this:

http://postimg.org/image/jg2f2zxm7/

My code:
    ostringstream ss;
    sf::Text text;

    text.setFont(font);
    text.setCharacterSize(15);
    text.setColor(sf::Color::Red);
    text.setStyle(sf::Text::Bold);
    text.setPosition(0,0);

//inside gameloop

//window.clear()

ss << "FPS: " << fps;
text.setString(ss.str())
window.draw(text);

//window.display()

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Draw fps with window.draw
« Reply #1 on: March 11, 2016, 09:01:53 pm »
ss.str("") to clear the ostringstream. But a better solution is to declare it only when you need it, inside the loop. This way you always start with a fresh stream, no need to deal with its previous content.
Laurent Gomila - SFML developer

angdrw

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Draw fps with window.draw
« Reply #2 on: March 11, 2016, 09:06:27 pm »
Thank you fixed the problem :)