I know that game loop is broken up into three distinct phases: processing inputs, update, and render, but I just can’t see how I can make processing input and update independent of each other.
Let’s say I have a button. If I click on the button, it will increment the number by one on the screen. How can I make this possible? Is it OK to update the logic while processing the input?
For example:
while (!ended)
{
while (SDL_PollEvent(&event))
{
IF MOUSE EVENT
IF USER CLICKED ON THE BUTTON
NUMBER += 1;
}
update(); // no job for update as number was incremented above
draw();
}
Why would I need a distinct update function if we could just update logic/values while processing input like the code above?
Please show me an example using SDL poll event system.
while (!ended)
{
while (SDL_PollEvent(&event))
{
}
update();
draw();
}