[solved] FPS Counter not calculating FPS correctly

Hello JGO, yesterday I revised my game loop thanks to BurntPizza :slight_smile:

I added a FPS Counter and it seems to be returning the wrong FPS?
It’s returning 59 fps when I set my desired fps to 60, although I’m not worried about my frame-rate I’m worried that my calculations aren’t returning the right number.

Here’s my game loop:


	protected static void startGameThread() {
		gameThreadRunning = true;
		gameThread = new Thread() {
			@Override
			public void run() {
				super.run();

				// Initialize our frameStart time outside of the loop :D
				frameStartTime = System.nanoTime();

				while (gameThreadRunning) {
					final long startTime = System.nanoTime();

					if ((System.nanoTime() - frameStartTime) / 1000000 >= 1000) {
						fps = frames;
						frames = 0;
						System.out.println("FPS: " + fps);
						frameStartTime = System.nanoTime();
					}

					// Update
					update();

					// Render
					render();
					frames++;

					while (System.nanoTime() < startTime + nanosToSleep) {
						try {
							Thread.sleep(1);
						} catch (final InterruptedException e) { }
					}
					// End while loop
				}
			}
		};
		gameThread.setName("GameThread01");
		gameThread.start();
	}

Thanks for any help guys :slight_smile: