I'm learning about the game development. No i'm on the total basics - writting a proper game loop
. As i've searched over the Web i'v found that simple but good working pattern using so called fixed time step:
double previous = getCurrentTime();
double lag = 0.0;
while (true)
{
double current = getCurrentTime();
double elapsed = current - previous;
previous = current;
lag += elapsed;
processInput();
while (lag >= MS_PER_UPDATE)
{
update();
lag -= MS_PER_UPDATE;
}
render();
}
I roughly understand the logic behind this piece of code but i have the question regarding the game composition. What exactly the update function do and what the render function. What's their responsibility? Am i assuming right that in the super simple 2D game the update function can for e.g. calculate the distance in pixels the object (e.g. a Car) should move in the next frame and the render function in such a case just takes this calculated position and draws the Car on the screen? Correct me if i'm wrong and please provide some example/s.
Thx.
PS. Sorry for such a basic question but i'm really beginner.
update
andrender
functions. Please... \$\endgroup\$