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

Pages: [1]
1
General / Re: How to Clock framing the game
« on: April 30, 2020, 01:55:30 pm »
Btw, I have trouble with animation and logic times, the animation plays too fast and when I set the clock time to more slowly, it breaks the logic times, and if I use two clocks one for logic one for drawing, it gets ugly and not smooth, what should I do?

void PacmanGame::run() {
        sf::Clock drawClock;
        sf::Time drawframeTime = sf::milliseconds(150);

        sf::Clock logicClock;
        sf::Time logicframeTime = sf::milliseconds(50);

        while (window.isOpen()) {
                sf::Time elapsedDraw = drawClock.getElapsedTime();
                sf::Time elapsedLogic = logicClock.getElapsedTime();

                if (elapsedLogic > logicframeTime) {
                        logic();
                        logicClock.restart();
                }

                if (elapsedDraw > drawframeTime) {                     
                        draw();
                        drawClock.restart();
                }
        }
}
 

2
General / How to Clock framing the game
« on: April 30, 2020, 08:51:11 am »
Hopefully this is the right place to ask,
I'm wondering if this is the proper way of doing this clock framing:
void game::run() {

        sf::Clock clock;
        sf::Time frameTime = sf::milliseconds(10);
        while (window.isOpen()) {
                sf::Time elapsed = clock.getElapsedTime();

                if (elapsed > frameTime) {
                        logic();
                        draw();
                        clock.restart();
                }
        }
}
 

Or this is done differently ?

Pages: [1]