Libgdx。用Pixmap用圆角填充ProgressBar

时间:2018-10-10 07:37:37

标签: android libgdx progress-bar desktop pixmap

我正在尝试使用Pixmap加载ProgressBar。

public static ProgressBar createUpProgressBar() {
        Pixmap pixmap = new Pixmap(PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT, Format.RGBA8888);
        pixmap.setColor(Color.RED);
        setUpEdges(pixmap);
        Texture texture = new Texture(pixmap);
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
        pixmap.dispose();
    ProgressBarStyle progressBarStyle = new ProgressBarStyle();
    progressBarStyle.background = drawable;

    pixmap = new Pixmap(PROGRESS_BAR_EDGES_RADIUS * 2 + 20, PROGRESS_BAR_HEIGHT, Format.RGBA8888);
    pixmap.setColor(Color.GREEN);
    setUpEdges(pixmap);
    texture = new Texture(pixmap);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    drawable = new TextureRegionDrawable(new TextureRegion(texture));

    pixmap.dispose();

    progressBarStyle.knob = drawable;
    progressBarStyle.knobBefore = drawable;

    ProgressBar progressBar = new ProgressBar(0.0f, 1.0f, 0.01f, false, progressBarStyle);
    progressBar.setValue(0.0f);
    progressBar.setAnimateDuration(0.25f);

    int x = GAME_WIDTH / 2 - PROGRESS_BAR_WIDTH / 2;
    progressBar.setBounds(x, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT);

    return progressBar;
}

private static void setUpEdges(Pixmap pixmap) {
    //link to solution: https://developerover30.wordpress.com/2014/11/11/libgdx-creating-a-rounded-rectangle-pixmap/
    // Pink rectangle
    pixmap.fillRectangle(0, PROGRESS_BAR_EDGES_RADIUS, pixmap.getWidth(),
                         pixmap.getHeight() - 2 * PROGRESS_BAR_EDGES_RADIUS);

    // Green rectangle
    pixmap.fillRectangle(PROGRESS_BAR_EDGES_RADIUS, 0, pixmap.getWidth() - 2 * PROGRESS_BAR_EDGES_RADIUS,
                         pixmap.getHeight());

    // Bottom-left circle
    pixmap.fillCircle(PROGRESS_BAR_EDGES_RADIUS, PROGRESS_BAR_EDGES_RADIUS, PROGRESS_BAR_EDGES_RADIUS);

    // Top-left circle
    pixmap.fillCircle(PROGRESS_BAR_EDGES_RADIUS, pixmap.getHeight() - PROGRESS_BAR_EDGES_RADIUS,
                      PROGRESS_BAR_EDGES_RADIUS);

    // Bottom-right circle
    pixmap.fillCircle(pixmap.getWidth() - PROGRESS_BAR_EDGES_RADIUS, PROGRESS_BAR_EDGES_RADIUS,
                      PROGRESS_BAR_EDGES_RADIUS);

    // Top-right circle
    pixmap.fillCircle(pixmap.getWidth() - PROGRESS_BAR_EDGES_RADIUS, pixmap.getHeight() - PROGRESS_BAR_EDGES_RADIUS,
                      PROGRESS_BAR_EDGES_RADIUS);
}
}

当我查看进度条中加载的15%时,它看起来不错

enter image description here

但是当我看到进度条几乎满载时,它看起来不正确

enter image description here

我们在 B 部分中正确地进行了最后划分。好像部分 A 将一个分区延伸到整个宽度。我希望每个部门都应该相互借鉴,以实现对ProgressBar的完全填充。

有人可以向我解释我错了吗?

0 个答案:

没有答案