	public void run(){
		Canvas canvas;
		Log.d(TAG, "Starting game loop");
		if(!(gamePanel == null)){
			while (running) {
				startTime = System.currentTimeMillis();
				gamePanel.update();
				canvas = null;
				try {
					canvas = this.surfaceHolder.lockCanvas();
					synchronized (surfaceHolder) {
						this.gamePanel.render(canvas);
					}
				} finally {
					if (canvas != null) {
						surfaceHolder.unlockCanvasAndPost(canvas);
					}
				} 
				endTime = System.currentTimeMillis();
				if(endTime - startTime <= updateInterval){
					try {
						Thread.sleep(updateInterval + startTime - endTime);
					} catch(InterruptedException e){}
				} else { 
					overTime = endTime - startTime - updateInterval;
					while(overTime >= 0){
						startTime = System.currentTimeMillis();
						gamePanel.update();
						endTime = System.currentTimeMillis();
						if(endTime - startTime <= updateInterval){
							try {
								Thread.sleep(updateInterval + startTime - endTime);
							} catch(InterruptedException e){};
						}
						overTime -= updateInterval + startTime - endTime;
					}
				}
			}
		} else {
			while (running) {
				startTime = System.currentTimeMillis();
				menuPanel.update();
				canvas = null;
				try {
					canvas = this.surfaceHolder.lockCanvas();
					synchronized (surfaceHolder) {
						if(canvas!=null)
						this.menuPanel.render(canvas);
					}
				} finally {
					if (canvas != null) {
						surfaceHolder.unlockCanvasAndPost(canvas);
					}
				} 
				endTime = System.currentTimeMillis();
				try {
					if(startTime - endTime > -updateInterval){
						Thread.sleep(updateInterval + startTime - endTime);
					}
				} catch(InterruptedException e){}
			}
		}
	}

	public void run(){
		Canvas canvas;
		Log.d(TAG, "Starting game loop");
		if(!(gamePanel == null)){
			while (running) {
				startTime = System.currentTimeMillis();
				gamePanel.update();
				canvas = null;
				try {
					canvas = this.surfaceHolder.lockCanvas();
					synchronized (surfaceHolder) {
						this.gamePanel.render(canvas);
					}
				} catch(NullPointerException e){}
				finally {
					if (canvas != null) {
						surfaceHolder.unlockCanvasAndPost(canvas);
					}
				} 
				endTime = System.currentTimeMillis();
				if(endTime - startTime <= updateInterval){
					try {
						Thread.sleep(updateInterval + startTime - endTime);
					} catch(InterruptedException e){}
				} else { 
					overTime = endTime - startTime - updateInterval;
					while(overTime >= 0){
						startTime = System.currentTimeMillis();
						gamePanel.update();
						endTime = System.currentTimeMillis();
						if(endTime - startTime <= updateInterval){
							try {
								Thread.sleep(updateInterval + startTime - endTime);
							} catch(InterruptedException e){};
						}
						overTime -= updateInterval + startTime - endTime;
					}
				}
			}
		} else {
			while (running) {
				startTime = System.currentTimeMillis();
				menuPanel.update();
				canvas = null;
				try {
					canvas = this.surfaceHolder.lockCanvas();
					synchronized (surfaceHolder) {
						this.menuPanel.render(canvas);
					}
				} catch(NullPointerException e){}
				finally {
					if (canvas != null) {
						surfaceHolder.unlockCanvasAndPost(canvas);
					}
				} 
				endTime = System.currentTimeMillis();
				try {
					if(startTime - endTime > -updateInterval){
						Thread.sleep(updateInterval + startTime - endTime);
					}
				} catch(InterruptedException e){}
			}
		}
	}
