我正在使用他们的Scene2d.ui包在libgdx中创建一个商店阶段。当我看到一些较大版本的按钮出现在较小的按钮后面时,我看到这个非常奇怪的闪烁:
较大的背景按钮闪烁,而前面的按钮看起来完全正常。背景的不是可点击的,但前面的是 - 它们看起来完全正常。
以下是相关代码:
private void init(Skin skin) {
this.skin = skin;
boyTexture = new Texture(Gdx.files.internal("images/character.png"));
catTexture = new Texture(Gdx.files.internal("images/character_cat_girl.png"));
hornTexture = new Texture(Gdx.files.internal("images/character_horn_girl.png"));
pinkTexture = new Texture(Gdx.files.internal("images/character_pink_girl.png"));
queenTexture = new Texture(Gdx.files.internal("images/character_queen_girl.png"));
// set root table
table = new Table();
table.setFillParent(true);
addActor(table);
table.add(new Label("Characters: ", skin, "default")).padLeft(10).colspan(2);
table.row();
ButtonGroup characterGroup = new ButtonGroup();
characterGroup.setMaxCheckCount(1);
Button boyButton = createImageTextButton("Plain Boy", boyTexture);
table.add(boyButton);
Button catButton = createImageTextButton("Cat Girl", catTexture);
table.add(catButton);
table.row();
Button hornButton = createImageTextButton("Horn Girl", hornTexture);
table.add(hornButton);
Button pinkButton = createImageTextButton("Pink Girl", pinkTexture);
table.add(pinkButton);
table.row();
Button queenButton = createImageTextButton("Queen", queenTexture);
table.add(queenButton).colspan(2);
//addAction(Actions.sequence(Actions.alpha(1f), Actions.fadeIn(1)));
}
private Button createImageTextButton(String label, Texture texture) {
ImageTextButton button = new ImageTextButton(label, skin, "default");
button.getImage().setDrawable(new SpriteDrawable(new Sprite(texture)));
return button;
}
起初我认为这与过渡行动有关,但正如你所看到的,我已将它们评论出来并且它仍在发生。
我还认为只是ImageTextButton存在问题,但我更改了createImageTextButton
方法以返回普通TextButton
。它仍然有一个闪烁,但按钮没有在背景中放大 - 它们看起来在两侧闪烁,但大小与前景相同。
以下是评论中所要求的构造函数:
public Store(Skin skin) {
super();
init(skin);
}
public Store(Viewport viewport, Skin skin) {
super(viewport);
init(skin);
}
public Store(Viewport viewport, Batch batch, Skin skin) {
super(viewport, batch);
init(skin);
}
我在MainGame课程中创建舞台时使用的是最后一个。
public class MainGame extends ApplicationAdapter {
public static final int MIN_WIDTH = 480;
public static final int MIN_HEIGHT = 800;
public static SpriteBatch batch;
public static GameStage game;
public static Store store;
public static Skin skin;
public static Viewport viewport;
public static Stage stage;
@Override
public void create() {
viewport = new ExtendViewport(MIN_WIDTH, MIN_HEIGHT);
batch = new SpriteBatch();
initSkin();
game = new GameStage(viewport, batch, skin);
store = new Store(viewport, batch, skin);
setStage(game);
}
...
@Override
public void render() {
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height, true);
}
...
public static void setStage(Stage stage) {
MainGame.stage = stage;
Gdx.input.setInputProcessor(stage);
}
}