private void draw() {
        BufferStrategy bs = getBufferStrategy();
        if (bs == null) {
            createBufferStrategy(3);
            return;
        }
        
        gfx.clearScreen();
        render();
        for (int k = 0; k < pixels.length; k++)
            pixels[k] = gfx.getPixel(k);
        
        Graphics g = bs.getDrawGraphics();
        try {
            Gfx.reset(g);
        } catch (IncorrectUsageException e) {
            e.printStackTrace();
        }
        g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
        renderForeground();
        g.dispose();
        try {
            Gfx.cleanUp();
        } catch (IncorrectUsageException e) {
            e.printStackTrace();
        }
        bs.show();
    }