1
General / How to make a game loop and draw the fps on the screen?
« on: April 11, 2021, 09:36:10 pm »
Hello, I've made the game loop from the SFML Game Development book. But now I want to figure out how to show the FPS on the screen. What is the right way of doing it?
int fps = 60;
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::Time timePerFrame = sf::seconds(1.f / fps);
while (window.isOpen())
{
timeSinceLastUpdate += clock.restart();
processEvents();
while (timeSinceLastUpdate > timePerFrame) // time per frame
{
timeSinceLastUpdate -= timePerFrame;
processEvents();
update(timePerFrame);
}
render();
}
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::Time timePerFrame = sf::seconds(1.f / fps);
while (window.isOpen())
{
timeSinceLastUpdate += clock.restart();
processEvents();
while (timeSinceLastUpdate > timePerFrame) // time per frame
{
timeSinceLastUpdate -= timePerFrame;
processEvents();
update(timePerFrame);
}
render();
}