大家好我正在嘗試使用Libgdx中的Table來顯示一些圖像,但它沒有正確顯示它們,我無法找到修復該問題的方法 當我使用table.bottom
時,它會顯示它們,但當我使用table.center
它顯示他們較低,當我選擇上,左或右它說明不了什麼 :這裏是我的代碼格式化表格:Libgdx表組件無法正確顯示
public class MenuIcons {
public Viewport viewport;
public Stage stage;
public boolean upPressed;
public boolean leftPressed;
public boolean rightPressed;
public boolean levellock1,levellock2;
public Image lock1;
public Image lock2;
public OrthographicCamera camera;
public Table table;
//Constructor.
public MenuIcons(SpriteBatch spriteBatch) {
camera = new OrthographicCamera();
viewport = new FitViewport(400, 208, camera);
stage = new Stage(viewport, spriteBatch);
Gdx.input.setInputProcessor(stage);
initalizeTable();
}
public void draw() {
stage.draw();
}
public void resize(int width, int height) {
viewport.update(width, height);
}
public void initalizeTable()
{
//Buttons with images.
lock1 = new Image(new Texture("levellock.png"));
lock1.setSize(25, 25);
lock1.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
levellock1 = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
levellock1 = false;
}
});
lock2 = new Image(new Texture("levellock.png"));
lock2.setSize(25, 25);
lock2.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
levellock2 = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
levellock2 = false;
}
});
//Table with buttons.
table = new Table();
table.bottom; //Align to the left bottom.
table.add();
table.add();
table.add();
table.add(lock1).size(lock1.getWidth(), lock1.getHeight());
table.add(lock2).size(lock2.getWidth(), lock2.getHeight());
stage.addActor(table);
}
public boolean isLevellock1() {
return levellock1;
}
public boolean isLevellock2() {
return levellock2;
}
}
這裏是圖像,當我使用Table.bottom
:
這裏是圖像,當我使用Table.center
:
我希望它是table.left()。但它並沒有工作。 我使用table.add在它們之間創建一些空格 –
您確實需要閱讀我的消息開頭鏈接的文檔,因爲它具有所有答案。看看我的編輯:你需要添加這個'table.setDebug(true);'所以你可以看到發生了什麼。 – sorifiend
謝謝,完成了 –