sf::RenderWindow window(sf::VideoMode(800, 600), "My Window"); while (window.isOpen()) { sf::Time frameTime = window.getFrameTime(); // do some calculations based on the frame time, e.g. smooth movement float movement = 100.f * frameTime.asSeconds(); // ... // draw the updated frame window.clear(); // ... window.display(); }
sf::RenderWindow window(sf::VideoMode(800, 600), "My Window"); while (window.isOpen()) { if (window.getFrameTime().asMilliseconds() > 16.6f) // cap framerate to 60 FPS { // do some game logic and rendering // ... } }Here, we're using `getFrameTime` to limit the frame rate of the application to 60 frames per second. If the time elapsed since the last frame is less than 16.6 milliseconds (1/60th of a second), we skip the frame. Package/library: SFML library.