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 - ScullCrusher

Pages: [1]
1
Graphics / Help with a severe lag
« on: August 08, 2020, 09:00:46 pm »
This is my first time using SFML and while I was trying to make a game I noticed that whenever I ran the program, everything on my computer would start lagging. I opened the Task manager and it said that the program was using a lot of the performance. I have reproduced the bug so that it's easier to read the code.
I know the problem is in the the update function because when I comment out it's call, it doesn't cause the lag.
Here is the code
#include "SFML/Graphics.hpp"


class Game
{
private:
        sf::RenderWindow* window;

public:
        Game()
                : window{ new sf::RenderWindow(sf::VideoMode(500, 500), "Game") }
        {

        }

        ~Game()
        {
                delete window;
        }

        void handleInputs()
        {
                sf::Event event;
                while (window->pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window->close();
                }
        }

        void update()
        {
                window->clear();
                window->display();
        }

        void run()
        {
                while (window->isOpen())
                {
                        handleInputs();
                        update();
                }
        }
};


int main()
{
        Game game;
        game.run();

        return 0;
}

 

Pages: [1]