public void run() {
	
		@SuppressWarnings("unused")
		int fps = 0, updates = 0;
		long fpsTimer = System.currentTimeMillis();
		double nsPerUpdate = 1000000000.0 / 60;

		// last update time in nano
		double then = System.nanoTime();
		double unprocessed = 0;
		while(running){
			boolean shouldRender = false;
			double now=System.nanoTime();
			unprocessed+=(now-then)/nsPerUpdate;
			then=now;
			
		// update queue
		while (unprocessed >= 1) {
			updates++;
			update();
			unprocessed--;
			shouldRender = true;
		}

		// render
		if (shouldRender) {
			fps++;
			render();
			shouldRender = false;
		} else {
			try {
				Thread.sleep(1);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if(System.currentTimeMillis()-fpsTimer>1000){
			fps=0;
			updates=0;
			fpsTimer+=1000;
		}
		}
		
	}