0
\$\begingroup\$

So what's better?

In case the title is a bit confusing I mean:

1) Drawing every window update interval. For example, for a 60FPS window, every 17 milliseconds. For example:

window.setFramerateLimit(60); //Update every 17 milliseconds for 60FPS
while(window.isOpen()) {
window.display();
}

Or

2) Drawing when you need to (for example, when a sprite moves) and displaying it straight after. For example:

void func(sf::RenderWindow& window) {
window.draw(sf::Sprite()); //Whatever you're drawing
window.display();
}

Or is there a much better way?

\$\endgroup\$
1
  • \$\begingroup\$ Edited for clarity. \$\endgroup\$
    – Jay
    Jul 24, 2015 at 14:06

1 Answer 1

1
\$\begingroup\$

You should draw everything, and swap the buffer (display), at most once per frame (usually 1/60th second).

You should definitely not call window.display() more than once per frame.

If nothing at all has moved, you might choose to skip drawing and displaying entirely for that frame, especially on a mobile device to conserve power. On a desktop, typically, may as well draw every frame, to keep the loading predictable.

Last note -- your game logic updates might or might not also be at the same 1/60th per second update. Easiest if they are, if possible.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .