对于libgdx UI API [英] UI API for libgdx

查看:163
本文介绍了对于libgdx UI API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android和这里libgdx小白。

Android and libgdx noob here.

有谁知道这是发布libgdx最近UI API什么? 在这里看到的博客文章:<一个href="http://www.badlogicgames.com/word$p$pss/?p=2058">http://www.badlogicgames.com/word$p$pss/?p=2058

Does anyone know anything about the recent UI API that was released for libgdx? See blog post here: http://www.badlogicgames.com/wordpress/?p=2058

我期待建立一个基本的菜单系统,我在想,如果这个UI API会更容易。

I am looking to create a basic menu system, and I was wondering if this UI API would make it easier.

推荐答案

更新,以反映更改LibGDX

我在一个类似的立场,下面code为我工作,以创建一个基本的菜单(按钮的容器)。在code是行不通的原样,因为它使用了一些我的课,但什么真正的问题是创造方法的内容。这就形成了一个中心标题,然后在容器中的一些按钮,被集中,然后fps的标签在左下角和右下角的图像。主题文件和一些图像是从 LibGDX测试资产

I am in a similar position, the following code worked for me to create a basic menu (A container of buttons). The code won't work as is, because it uses some of my classes, but what really matter is the content of the create method. This creates a centered title, then some buttons in a container that gets centered, then fps label in the lower left and an image in the lower right corner. The theme files and some of the images are from the LibGDX tests assets.

我已经得到了这个与JOGL,LWJGL和Android应用程序类的工作。我在Droid 2的运行它,并得到了,因为它没有我的桌面上运行。这应该可以让你开始。

I've gotten this to work with the JOGL, LWJGL, and android application classes. I've run it on a Droid 2 and got it to run as it did on my desktop. Hopefully this should get you started.

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);
}

这篇关于对于libgdx UI API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆