public void run() {
		int frames = 0;
		int tickCount = 0;
		
		double delta = 0;
		double secondsPerTick = 1 / 60.0;
		
		long lastTime = System.nanoTime();
		
		requestFocus();
		
		while(running) {
			long now = System.nanoTime();
			long elapsedTime = now - lastTime;
			lastTime = now;
			if (elapsedTime < 0)
				elapsedTime = 0;
			if (elapsedTime > 100000000)
				elapsedTime = 100000000;
			delta += elapsedTime / 1000000000.0;

			boolean ticked = false;
			while (delta > secondsPerTick) {
				tick();
				delta -= secondsPerTick;
				ticked = true;

				tickCount++;
				if (tickCount % 60 == 0) {
					System.out.println(frames + " fps");
					lastTime += 1000;
					frames = 0;
				}
			}

			if (ticked) {
				render();
				frames++;
			} else {
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}