2017-07-31 4 views
0

私はこのようにする必要があるプロジェクトを持っています:libgdxでタイトルバーを使わないでウィンドウを作成するには

enter image description hereウィンドウを使用して

私はどのようにすることができ、私は私の質問次のコード

private Table buildControlsWindowLayer() { 
     Window window = new Window("", skinLibgdx); 
     // + play button 
     playButton = new Button(maputoSkin, "play"); 
     window.add(playButton).pad(10, 0, 10, 0).row(); 
     playButton.addListener(listener); 
     // + options button 
     optionsButton = new Button(maputoSkin, "options"); 
     window.add(optionsButton).pad(10, 0, 10, 0).row(); 
     optionsButton.addListener(listener); 
     // + leaders button 
     leadersButton = new Button(maputoSkin, "leaders"); 
     window.add(leadersButton).pad(10, 0, 10, 0).row(); 
     leadersButton.addListener(listener); 
     if (Constants.DEBUG_FLAG_MENU_SCREEN) window.debug(); 
     window.pack(); 
     window.setPosition(Constants.VIEWPORT_GUI_WIDTH/2 - window.getWidth()/2, 
          Constants.VIEWPORT_GUI_HEIGHT/2 - window.getHeight()); 
     return window; 
    } 

I.を上記の結果を作成しています次の結果

enter image description here

を取得タイトルバーを取り除く

II。 libgdxの代わりに自分自身の背景を設定するにはどうすればいいですか

III。このアプローチは第3の状況に対して正しいですか?

答えて

0

私のアプローチではなく、ウィンドウのテーブルを使用して、皮膚

Skin skin = SkinManager.getInstance().getSkin(); 
    final Table outerTable = new Table(); 
    outerTable.setFillParent(true); 
    stage.addActor(outerTable); 

    // Layer to hold the buttons and dark background 
    Table buttonsTable = new Table(); 

    playButton = new TextButton("Play", skin, "play"); 
    settingsButton = new TextButton("Setting", skin, "setting"); 
    highScoreButton = new TextButton("Leaders", skin, "leaders"); 

    buttonsTable.add(playButton).width().height().pad(); 
    buttonsTable.row(); 
    buttonsTable.add(settingsButton).width().height().pad(0); 
    buttonsTable.row(); 
    buttonsTable.add(highScoreButton).width().height().pad(); 
    buttonsTable.row(); 
    // + background color 
    buttonsTable.setBackground(controlsBackground); 

    // Adding button table to outer table 
    outerTable.add(buttonsTable).colspan(2).expand(); 

からninepatch描画可能として、その背景を定義し、彼らはあなたの世界の大きさに依存しているため、私はwidth()height()と空pad()を残しました。 そして一つのもの

controlsBackground = new NinePatchDrawable(new NinePatch(
       SkinManager.getInstance().getSkin().getRegion("menu-background"), 10, 10, 10, 10 
     )); 
1

com.badlogic.gdx.scenes.scene2d.ui.Windowにはコンストラクタが付属します:Window(java.lang.String title, Window.WindowStyle style) また、setStyle(Window.WindowStyle style)メソッドもあります。 Window.WindowStyleクラスでは、このウィンドウの背景を含むスタイルを定義できます。

「モーダルウィンドウとしてドラッグと作用することができる上部パディングがウィンドウのタイトルの高さとして使用されるテーブル」libgdxs DOCに従って(https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Window.WindowStyle.html)タイトルバーとして

ウィンドウであります私はタイトルバーを取り除く直接的な方法は見つけられませんでしたが、ウィンドウクラスを拡張すると、その機能のいくつかをオーバーライドして目的の結果を得ることができます。その出所を確認してください:https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java

3番目の質問に答えるには、より多くの情報を提供する必要があります。この状況ではどういう意味ですか?

0
private Table buildControlsWindowLayer() { 
     SpriteDrawable bgDrawble=new SpriteDrawable(new Sprite(createTexture(120, 400, Color.BLACK, 1))); 
     WindowStyle windowStyle=new WindowStyle(new BitmapFont(), Color.GREEN, bgDrawble); 
     Window window = new Window("", windowStyle); 
     // window.setWidth(0); 
     // + play button 
     SpriteDrawable upDrawble=new SpriteDrawable(new Sprite(createTexture(100, 40, Color.RED, 1))); 
     SpriteDrawable downDrawble=new SpriteDrawable(new Sprite(createTexture(100, 40, Color.RED, 1))); 
     SpriteDrawable cheDrawble=new SpriteDrawable(new Sprite(createTexture(100, 40, Color.RED, 1))); 
     TextButtonStyle btStyle=new TextButtonStyle(upDrawble, downDrawble, cheDrawble, new BitmapFont()); 
     TextButton playButton = new TextButton("play",btStyle); 
     window.add(playButton).pad(10, 0, 10, 0).row(); 
     //playButton.addListener(listener); 
     // + options button 
     TextButton optionsButton = new TextButton("options",btStyle); 
     window.add(optionsButton).pad(10, 0, 10, 0).row(); 
     // optionsButton.addListener(listener); 
     // + leaders button 
     TextButton leadersButton = new TextButton("leaders",btStyle); 
     window.add(leadersButton).pad(10, 0, 10, 0).row(); 
     //leadersButton.addListener(listener); 
     /// if (Constants.DEBUG_FLAG_MENU_SCREEN) window.debug(); 
     window.pack(); 
     // window.getTitleTable() ; 
     return window; 
    } 



public static Texture createTexture(int width, int height, Color col, 
      float alfa) { 
     Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); 
     Color color = col; 
     pixmap.setColor(color.r, color.g, color.b, alfa); 
     pixmap.fillRectangle(0, 0, width, height); 

     Texture pixmaptexture = new Texture(pixmap); 
     return pixmaptexture; 
    } 
関連する問題