SFML community forums
Help => General => Topic started by: Contadotempo on October 31, 2010, 06:07:02 pm
-
Hi,
I'm trying to make a function that would draw how many FPS were displayed each second.
The original function is:
double app_properties::draw_fps()
{
stringstream ss;
getfps=1/(App.GetFrameTime()); //getfps is a float declared in the app_properties class
ss << getfps;
dfps.SetText("FPS: " + (ss.str()).substr(0,2)); //dfps is a font string declared in the app_properties class
App.Draw(dfps);
return getfps;
}
How could I change this and make it draw the FPS only each second?
This is probably very easy to do, but I'm being dumb...
Thanks in advance!
-
You have to add two parameters. A counter and clock.
When the clock equal 1s, else draw counter and reset clock and counter.
:wink:
-
And you also could use static variable. like that
int app_properties::draw_fps()
{
static bool init = false;
static sf::Clock clock;
if(init == false)
{
init = true;
clock.reste();
}
getfps=1/(App.GetFrameTime()); //getfps is a float declared in the app_properties class
if(clock.GetEllapsedTime() >= 1.0)
{
clock.reste();
stringstream ss;
ss << getfps;
dfps.SetText("FPS: " + (ss.str()).substr(0,2)); //dfps is a font string declared in the app_properties class
App.Draw(dfps);
}
return getfps;
}
-
Aah, that was quite simple after all.
Thank you both :wink: