SFML community forums

Help => Window => Topic started by: angdrw on March 11, 2016, 08:53:25 pm

Title: Draw fps with window.draw
Post by: angdrw 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/)
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()
Title: Re: Draw fps with window.draw
Post by: Laurent 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.
Title: Re: Draw fps with window.draw
Post by: angdrw on March 11, 2016, 09:06:27 pm
Thank you fixed the problem :)