@SuppressWarnings("static-access")
	@Override
	public void run() {
		while (gameLoop.isAlive()) {
			beforeTime = System.nanoTime();

			gamePanel.update();
			gamePanel.paint();
			gamePanel.render();

			afterTime = System.nanoTime();
			deltaTime = afterTime - beforeTime;
			sleepTime = (period - deltaTime) - overSleepTime;

			if (sleepTime < period && sleepTime > 0) {
				try {
					gameLoop.sleep(sleepTime / 1000000L);
					overSleepTime = 0;
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} else if (deltaTime > period) {
				overSleepTime = deltaTime - period;
			} else if (++delays >= TICKS_BEFORE_WAIT) {
				gameLoop.yield();
				delays = 0;
				overSleepTime = 0;
			} else {
				overSleepTime = 0;
			}

			/*System.out.println("Before Time:	" + beforeTime + "\nAfterTime:	"
					+ afterTime + "\nDeltaTime:	" + deltaTime + "\nSleepTime:	"
					+ sleepTime / 1000000L + "\nOverSleepTime:	" + overSleepTime / 1000000L
					+ "\nDelays:	" + delays + "\n");*/
		}
	}