private void loop(){
		while(true){
			try{
				lastTime = curTime;
				curTime = System.currentTimeMillis();
				totalTime += curTime - lastTime;
				if(totalTime > 1000){
					totalTime -= 1000;
					fps = frames;
					frames = 0;
				} 
				++frames;
			        
				beginTime = System.currentTimeMillis();

				//Draw the buffer.
				Constants.getGameCanvas().draw();			
					
				timeTaken = System.currentTimeMillis() - beginTime;
				timeLeft = (UPDATE_PERIOD - timeTaken);
		
				if(timeLeft < 10) timeLeft = 10;
				
				try {
					Thread.sleep(timeLeft);
				}catch(InterruptedException ex){break;}
			}catch(Exception e){}
		}
	}