14

Androidとlibgdxnoobはこちら。

libgdx用にリリースされた最近のUIAPIについて誰か知っていますか?こちらのブログ投稿を参照してください:http ://www.badlogicgames.com/wordpress/?p = 2058

基本的なメニューシステムを作成したいと思っていますが、このUIAPIを使用すると簡単になるのではないかと考えていました。

4

2 に答える 2

24

LibGDXへの変更を反映するように更新されました

私も同じような立場にあり、次のコードで基本的なメニュー(ボタンのコンテナー)を作成できました。一部のクラスを使用しているため、コードはそのままでは機能しませんが、実際に重要なのはcreateメソッドの内容です。これにより、中央に配置されたタイトルが作成され、次に中央に配置されるコンテナ内にいくつかのボタンが作成され、左下にfpsラベルが作成され、右下隅に画像が作成されます。テーマファイルと一部の画像は、LibGDXテストアセットからのものです。

これは、JOGL、LWJGL、およびandroidアプリケーションクラスで機能するようになりました。Droid 2で実行し、デスクトップと同じように実行しました。うまくいけば、これで始められるはずです。

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

于 2011-07-25T01:11:08.543 に答える
7

はい、新しいUIAPIは非常に使いやすいです。Skinオブジェクトを使用してActorオブジェクトを作成し、それらをStageオブジェクトに結合することができ ます。

libgdxソースでUITest.javaファイルを参照できます。基本的なUI要素の使用方法を示します。

低レベルからlibgdxの新しいUIを確認するには、次の要素のみが含まれています。

  • NinePatch:要素を作成するための基本的な形状オブジェクトは伸びることがあります。
  • 領域:固定サイズ要素の形状オブジェクト。
  • フォント:表示テキスト用のbitmapfontオブジェクト。

Buttonオブジェクトなどの高レベルの要素は、ninepatchやfontojbectなどを含みます。

したがって、それらを使用して2DUIを非常に簡単に作成できます。:)

于 2011-09-03T06:01:58.850 に答える