public void run() {
		double ticksPerSecond = 60;
		int nanoSecondsPerTick = (int) (1000000000/ticksPerSecond);
		
		long timePassed = 0;
		long lastTime = System.nanoTime();
		long now;
		
		long tickTimer = System.currentTimeMillis();
		
		while (running) {
			now = System.nanoTime();
			timePassed += now - lastTime;
			lastTime = now;
			boolean ticked = false;
			
			while (timePassed >= nanoSecondsPerTick) {
				timePassed -= nanoSecondsPerTick;
				ticked = true;
			}
			
			if (ticked) {
				ticks++;
				tick();
				repaint();
			}
			
			if (System.currentTimeMillis() - tickTimer > 1000) {
				tickTimer += 1000;
				fps = ticks;
				ticks = 0;
			}
			
			try {
				Thread.sleep(2);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}