@Override
    public void run() {
        long lastLoopTime = System.nanoTime();
        final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
        long lastFpsTime = 0;
        fps = 0;
        counter = 0;
        while (true) {
            try {
                //<editor-fold defaultstate="collapsed" desc="all update">
                if (!gui.paused) {// work out how long its been since the last update, this
                    // will be used to calculate how far the entities should
                    // move this loop
                    long now = System.nanoTime();
                    long updateLength = now - lastLoopTime;
                    lastLoopTime = now;
                    double delta = updateLength / ((double) OPTIMAL_TIME);

                    // update the frame counter
                    lastFpsTime += updateLength;
                    fps++;

                    // update our FPS counter if a second has passed since
                    // we last recorded
                    if (lastFpsTime >= 1000000000) {
                        if (gui.debug) {
                            gui.debugText.setText("<html>FPS: " + fps + "<br>Scroll Position: " + gui.gameDisplay.getHorizontalScrollBar().getValue() + "<br>Player Location: " + player.location + "</html>");
                        } else {
                            gui.debugText.setText(null);
                        }
                        System.out.println("(FPS: " + fps + ")");
                        lastFpsTime = 0;
                        fps = 0;
                    }

                    // update the game logic
                    doGameUpdates(delta);
                    render();
                    try {
                        Thread.sleep((lastLoopTime - System.nanoTime() + OPTIMAL_TIME) / 1000000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(gameUpdates.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                //</editor-fold>
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }
    }