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 ?
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();
}
}
}