I'm trying to draw the fps for my game using sf::Text and sf::Clock.
Here is my code:
float Framerate = 1.f / rWindow.GetFrameTime() * 1000;
float time = timer.GetElapsedTime();
std::stringstream ss;
ss << "FPS: " << Framerate << "Time: " << time;
std::string fRString = ss.str();
if(time > 2000.f)
{
text.SetString(fRString);
timer.Reset();
}
ss.str("");
text.Move(View2.GetCenter().x - (View2.GetSize().x / 2 - 1), View2.GetCenter().y - (View2.GetSize().y / 2 - 1));
With sf::Text text and sf::Clock timer declared outside of the game loop.
This does not work. I can see the text get drawn once and than never again.
If I move the sf::Text text to be constructed within the game-loop instead of main it works. What am I doing wrong? Timer still works outside of the game loop so I guess I am just missing something. I'm obviously trying to construct my text outside of the game loop to capture fps and stop it from updating every frame, with it in the loop it just updates to fast to read.