libgdx ProgressBar旋转不起作用

时间:2015-01-07 05:20:55

标签: java rotation libgdx actor

.setRotation()或.rotateBy()函数适用于其他Actor类,但不适用于ProgressBar对象。

我在这里错过了什么吗?

public void create() {
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    skin = new Skin();
    Pixmap pixmap = new Pixmap(10, 10, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    TextureRegionDrawable textureBar = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("blue.jpg")))); // Just a blue square
    ProgressBar.ProgressBarStyle barStyle = new ProgressBar.ProgressBarStyle(skin.newDrawable("white", Color.DARK_GRAY), textureBar);
    progressBar = new ProgressBar(0,10,0.5f,false, barStyle);
    progressBar.setPosition(10, 10);
    progressBar.setSize(290, progressBar.getPrefHeight());
    progressBar.setAnimateDuration(2);
    progressBar.setValue(5);
    progressBar.setRotation(45); // Should rotate the bar

    stage.addActor(progressBar);
}

The bar stays horizontal even if I set the rotation.

另外,如果我调用.getRotation(),我得到了之前设置的内容,所以我不确定这里有什么问题。

1 个答案:

答案 0 :(得分:0)

Most UI widgets cannot be transformed directly,由于表现原因。仍然有旋转的getter / setter,这可能会令人困惑。

但是可以将它们放在Group中并转换组。

ProgressBar progressBar = ...
Group g = new Group();
g.addActor(progressBar);
g.setRotation(45);

stage.addActor(g);