Hey everyone!
I am currently having a problem with my first LWJGL program (a Pong game based off of chman’s awesome tutorials).
I set my main loop to look like this:
// main game loop
while(gameState != GAME_STATE_FINISHED) {
fpsControl.beforeLoop = System.nanoTime();
if(Display.isCloseRequested()) /* windows has been closed? */ {
System.exit(0);
}
updateGame(fpsControl.completeLoopTime);
renderGame();
fpsControl.afterLoop = System.nanoTime();
fpsControl.partialLoopTime = fpsControl.afterLoop - fpsControl.beforeLoop;
gameSleep();
fpsControl.completeLoopTime = System.nanoTime() - fpsControl.beforeLoop;
fpsControl.getFPS();
}
Whenver updateGame() is run, it checks to see if the game should be updated this loop (based on the amount of time since the last loop). The desired UPS is set at 60 for now.
The renderGame() code looks like this:
public void renderGame() {
if(fpsControl.gameUpdated) {
render();
Display.update();
}
}
Very simple, as you see. If the game has been updated at all this loop (via a variable set in UpdateGame), then it renders and updates the display.
However, in practice, this method of rendering only when the game is updated produces a slight, continuous stutter, most noticeable for the ball as it is moving around. Just enough to notice and be annoying.
With the if clause removed from renderGame(), the animation works fine and without stutter.
Could anyone please help me figure this one out?
I hope I have included enough information, but please do tell me if I left something important out ;D.
Thanks in advance,
Smarto