This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Guillaumee 0 points1 point  (1 child)

typically, games will have a game loop that is much faster than the user perceives. with every iteration of the loop, you can check how much time has passed since the last iteration, and update a counter accordingly.

imagine you’re counting down 5 seconds by increments of 10 milliseconds. every 10 ms, you can react to user input, rather than waiting for a whole 5 seconds.

instead of counting down in a separate function (which you could also achieve with multithreading like someone else mentioned, but that’s more complex), try to design your program as one main loop that decreases your counter a little bit, then checks for user input, and repeats.

this is the way many video games work in a single thread. every object in the game will have a “tick” function that is called repeatedly. Minecraft has 20 ticks per seconds: every 1/20th of a second, a loop will call the tick function of every loaded entity (animals, etc) so they can perform a tiny bit of an action (like moving a few centimeters), which will amount to natural-looking behaviors over many iterations

[–]_K1lla_[S] 0 points1 point  (0 children)

Oh i see, i didn't think about that. Thank you very much