Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mago

Pages: [1]
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();
        }
 


Pages: [1]
anything