@Override
	public void run() {
		// Get the graphics context for the background.
		backgroundGraphics = (Graphics2D) background.getGraphics();

		// Determine how many milliseconds to wait in between drawings.
		long fpsWait = (long) (1.0 / targetFPS * 1000);
		main: while (gameRunning) {
			long renderStart = System.nanoTime();
			updateGame();

			// Update graphics.
			do {
				// Get the background graphics to render on.
				Graphics2D bg = getBuffer();

				// If the game isn't running, exit.
				if (!gameRunning) {
					break main;
				}

				// Render it.
				renderGame(backgroundGraphics); // this calls your draw method

				// Account for scale.
				if (scale != 1) {
					bg.drawImage(background, 0, 0, width * scale, height
							* scale, 0, 0, width, height, null);
				} else {
					bg.drawImage(background, 0, 0, null);
				}
				bg.dispose();
			} while (!updateScreen());

			// Calculate the time it took to render this frame for FPS limiting.
			long renderTime = (System.nanoTime() - renderStart) / 1000000;

			// Limit FPS so as not to exceed superhuman speeds.
			try {
				// Sleep if possible. If rendering took longer than expected (so
				// the second argument is negative), don't sleep at all.
				Thread.sleep(Math.max(0, fpsWait - renderTime));
			} catch (InterruptedException e) {
				// If we were interrupted, we can go back to the main loop.
				// Clear the interrupted status.
				Thread.interrupted();
				break;
			}

			// If needed:
			lastFrameRenderNanos = System.nanoTime() - renderStart;
		}

		// When done, dispose of the frame.
		cleanupGUI();
	}