libGDX进度条

时间:2017-03-08 04:04:02

标签: java libgdx progress-bar

我只发现了几个关于此问题的主题,看起来我所拥有的一切都是正确的,但它并不起作用。

public Block(Body body, int x, int y, Player player, GameStage stage, GameScreen screen)
{
    ...

    bar = progressBar();

    stage.addActor(this);
    stage.addActor(bar);
}

public ProgressBar progressBar()
{
    ProgressBar.ProgressBarStyle barStyle;
    TextureRegionDrawable textureBar;
    Skin skin = new Skin();

    Pixmap pixmap = new Pixmap(10, 10, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();

    skin.add("white", new Texture(pixmap));
    textureBar = new TextureRegionDrawable(new TextureRegion(new Texture("bar.png")));
    barStyle = new ProgressBar.ProgressBarStyle(skin.newDrawable("white", Color.DARK_GRAY), textureBar);
    barStyle.knobBefore = barStyle.knob;

    bar = new ProgressBar(0f, maxHitPoints, maxHitPoints/30, false, barStyle);
    bar.setPosition(this.x, this.y);
    bar.setSize(20, 5);
    bar.setAnimateDuration(2);

    return bar;
}

public void draw(Batch batch, float parentAlpha)
{
    super.draw(batch, parentAlpha);

    batch.setColor(blockColor);
    batch.draw(region, this.getX(), this.getY());

    batch.setColor(Color.WHITE);
    bar.setValue(hitPoints);

}

stage.act和stage.draw在别处被调用但被调用。

我得到了一个坚实的栏,但我尝试的任何东西都没有让它填补/取消

我想我一定会错过一些愚蠢的东西,但对于我的生活,我无法找到答案。

0 个答案:

没有答案