大家好我正在尝试使用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
谢谢,完成了 –