First off hi guys, haven’t posted here in a while. OK here is the thing: a while back I figured out ho the game loop and rendering loop were supposed to work. It ran fine on my machine and a few of the other members as well. But some people experienced stutter, which was caused by my code’s poor handling of lag. I figured out the problem and a solution, which is a rudimentary one, but now think that my design is the flaw. Here is the problem and solution:
I have the game tick, client tick loop designed by Marcus Person. I use the game tick to check the keyboard and update the player’s position. The problem is that if there is lag and multiple game ticks happen sequentially, then the character’s position is updated multiple times, without a rendering, so when the render phase finally gets called in client tick, the character jumps to the new position, creating a stutter looking effect.
My rudimentary solution is to create a flag that keeps track making sure that if a game tick happens after a game tick with no client ticks at all in between, then the position update does not happen. This solution is of course crude and slow. This leads me to the following conclusion.
I think that my design is wrong. Currently I have a loop that has a character.update() call in the game tick. The character class checks the keyboard and figures out the new position of the character. I believe this to be the wrong approach. I was wondering what others thought about how to properly abstract the different game mechanics. Which part of the game application should be checking if the direction key is down?