public void gameLoop() {

        long lastTime = System.nanoTime();
        long cycleTime;
        final double amountOfTicks = 60.0;
        double ns = 1000000000 / amountOfTicks; // number of nanoseconds per ticks
        double delta = 0;
        int updates = 0;
        int frames = 0;
        long timer = System.currentTimeMillis();

        cycleTime = System.currentTimeMillis();

        while (playing) {
            long now = System.nanoTime();
            delta += (now - lastTime) / ns;
            lastTime = now;
            if (delta >= 1) { // update
                tick();
                updates++;
                delta--;
            }
            render();
            repaint();
            frames++;
            if (System.currentTimeMillis() - timer > 1000) { // reset every second
                timer += 1000;
                ticks = updates;
                fps = frames;
                //System.out.println(updates + "Ticks, Fps" + frames);
                updates = 0;
                frames = 0;
            }
            cycleTime = synchroFramerate(cycleTime);
        }
    }