most likely a dumb question, but can't you both update and redraw everything at once in a single function rather than calling two functions back to back, what's the advantage of updating then drawing?
-
Might want to see http://gamedev.stackexchange.com/ – bobobobo Jan 14 '14 at 00:59
-
The same reason you don't write all your code in one big `main` function! – Blorgbeard Jan 14 '14 at 01:04
-
4This question is definitely NOT opinion-based. He's asking for the advantage of keeping Update and Draw separate. It is because when the game lags, Update() can be called reliably and Draw() can be called less often to reduce lag without reducing responsiveness. – Mar 23 '14 at 17:21
2 Answers
Update is not meant for drawing or any output like this,
but instead for game logic etc.etc.
One of the benefits of separating this two things
(other than cleaner program structure and so on) is, for example,
that if the game is too slow, Update can be called multiple times
before a Draw. The game graphic will probably lag,
but at least the logic behind will be in time.

- 11,268
- 3
- 32
- 49
both update and redraw everything at once in a single function
You can do a lot of things in a single function. But you shouldn't. It gives the function too many responsibilities, too many dependancies, and makes it a lot less re-usable.
Updating game state is a responsibility of the game logic. Re-drawing the screen is a responsibility of the user interface. Both should be kept very separate. This allows them to change independently of one another without affecting each other.

- 208,112
- 36
- 198
- 279