@Override
	public void run() {
			while(true){
				beforeTime = System.nanoTime();
				
				gameUpdate();
				gameRender();
				paintScreen();
				
				afterTime = System.nanoTime();
				diff = afterTime - beforeTime;
				sleepTime = (period - diff) - overSleepTime;	
				if(sleepTime < period && sleepTime > 0){
					try {
						Thread.sleep(sleepTime / 1000000L);
						overSleepTime = 0;
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}else if(diff > period){
					overSleepTime = diff - period;
				} else if(++delays >= DELAYS_BEFORE_YIELD){
					Thread.yield();
					overSleepTime = 0;
				} else{
					overSleepTime = 0;
				}
			}
	}