cập nhật để phản ánh thay đổi đối với LibGDX
Tôi đang ở một vị trí tương tự, các mã sau đây làm việc cho tôi để tạo ra một menu cơ bản (A container của nút). Mã sẽ không hoạt động như vậy, bởi vì nó sử dụng một số lớp của tôi, nhưng điều thực sự quan trọng là nội dung của phương thức tạo. Điều này tạo tiêu đề lấy nét, sau đó một số nút trong vùng chứa được căn giữa, sau đó là nhãn fps ở phía dưới bên trái và hình ảnh ở góc dưới bên phải. Các tệp chủ đề và một số hình ảnh là từ LibGDX tests assets.
Tôi đã làm việc này với các lớp ứng dụng JOGL, LWJGL và android. Tôi đã chạy nó trên một Droid 2 và có nó chạy như nó đã làm trên máy tính để bàn của tôi. Hy vọng rằng điều này sẽ giúp bạn bắt đầu.
public class MenuScreen extends Screen{
private Stage ui;
private Table window;
@Override
public void create(final Game game) {
super.create(game);
TextureRegion image = new TextureRegion(new Texture(Gdx.files.internal(Art.badlogicSmall)));
Label fps = new Label("fps: ", Art.sSkin.getStyle(LabelStyle.class),"fps");
ui = new Stage(Gdx.graphics.getWidth(),Gdx.graphics.getHeight(), true);
Gdx.input.setInputProcessor(ui);
window = new Table("window");
window.width = ui.width();
window.height = ui.height();
window.x = 0;
window.y = 0;
window.debug();
Label title = new Label("Title",Art.sSkin.getStyle(LabelStyle.class),"title");
Button newGame = new Button("New Game",Art.sSkin.getStyle(ButtonStyle.class),"new");
newGame.setClickListener(new ClickListener() {
@Override
public void click(Actor actor) {
game.setScreen(GameScreen.class);
}
});
Button optionMenu = new Button("Option",Art.sSkin.getStyle(ButtonStyle.class),"Options");
Button helpMenu = new Button("Help",Art.sSkin.getStyle(ButtonStyle.class),"Help");
Image libgdx = new Image("libgdx", image);
window.row().fill(false,false).expand(true,false).padTop(50).padBottom(50);
window.add(title);
Table container = new Table("menu");
container.row().fill(true, true).expand(true, true).pad(10, 0, 10, 0);
container.add(newGame);
container.row().fill(true, true).expand(true, true).pad(10, 0, 10, 0);
container.add(optionMenu);
container.row().fill(true, true).expand(true, true).pad(10, 0, 10, 0);
container.add(helpMenu);
window.row().fill(0.5f,1f).expand(true,false);
window.add(container);
Table extras = new Table("extras");
extras.row().fill(false,false).expand(true,true);
extras.add(fps).left().center().pad(0,25,25,0);
extras.add(libgdx).right().center().pad(0,0,25,25);
window.row().fill(true,false).expand(true,true);
window.add(extras).bottom();
ui.addActor(window);
}
@Override
public void render(float arg0) {
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
((Label)ui.findActor("fps")).setText("fps: " + Gdx.graphics.getFramesPerSecond());
ui.act(Math.min(Gdx.graphics.getDeltaTime(), 1/30f));
ui.draw();
Table.drawDebug(ui);
}
@Override
public void resize(int width, int height) {
ui.setViewport(width, height, true);
Log.d("Resize: "+width+", "+height);
}
Thanks.This thực sự cần trợ giúp – kachilous