2013-03-21 65 views
1

我正在編寫一個LibGDX處理Backgroundtext的新程序,並且剛剛開始實現這些屏幕。但是當我測試它時,它只顯示給定分辨率的黑屏。 我使用setScreen(屏幕) - 實現的Game類中的方法調用屏幕。LibGDX Tablelayout菜單不顯示

所以這裏是代碼:

public class MenuScreen implements Screen{ 
Table table; 
Stage stage; 
TextButton button; 
TextField textField; 
Texture texture; 
Pic2Box2d game; 

public MenuScreen(Pic2Box2d gameH) 
{ 
    this.game = gameH; 
    stage = new Stage(0, 0, true); 
    table = new Table(); 
} 
public void create() 
{ 
    final TextFieldStyle fieldStyle = new TextFieldStyle(new BitmapFont(), Color.WHITE, new BitmapFont(), Color.GRAY, null, null, null); 
    textField = new TextField("path", fieldStyle); 
    final TextButtonStyle buttonStyle = new TextButtonStyle(); 
    buttonStyle.font = new BitmapFont(); 
    buttonStyle.fontColor = Color.WHITE; 
    buttonStyle.pressedOffsetY = 1f; 
    buttonStyle.downFontColor = new Color(0.8f, 0.8f, 0.8f, 1f); 
    button = new TextButton("Übernehmen", buttonStyle); 
    button.setClickListener(new ClickListener() { 
     @Override 
     public void click(Actor actor, float x, float y) { 
      if(textField.getText() != "" && textField.getText() != "path") 
      { 
      texture = new Texture(textField.getText()); 
      game.setScreen(new Workscreen(texture)); 
      } 
     } 
    }); 
    table.row(); 
    table.add(textField); 
    table.add(button); 
    stage.addActor(table); 
} 
@Override 
public void render(float delta) { 
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    Gdx.gl.glClearColor(0, 0, 0, 1); 
    stage.act(Gdx.graphics.getDeltaTime()); 
    stage.draw(); 
} 

}

回答

2

@idaNakav關於使用show()和設置階段尺寸是正確的。但是,這仍然會給你一個黑屏,因爲你的桌子沒有任何大小。嘗試更改您的顯示()代碼以包含table.setFillParent(true)

它應該看起來像這樣(代碼基於您提供的示例)。

@Override 
public void show() { 
    final TextFieldStyle fieldStyle = new TextFieldStyle(new BitmapFont(), Color.WHITE, null, null, null); 
    textField = new TextField("path", fieldStyle); 
    final TextButtonStyle buttonStyle = new TextButtonStyle(); 
    buttonStyle.font = new BitmapFont(); 
    buttonStyle.fontColor = Color.WHITE; 
    buttonStyle.pressedOffsetY = 1f; 
    buttonStyle.downFontColor = new Color(0.8f, 0.8f, 0.8f, 1f); 
    button = new TextButton("Übernehmen", buttonStyle); 
    button.addListener(new ClickListener() { 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      if (textField.getText() != "" && textField.getText() != "path") { 
       texture = new Texture(textField.getText()); 
       game.setScreen(new Workscreen(texture)); 
      } 
     } 
    }); 


    table.row(); 
    table.add(textField); 
    table.add(button); 

    // Make the table fill the stage. 
    table.setFillParent(true); 

    stage.addActor(table); 
} 
+0

這就是它...除了忘記我的「遊戲」類中的「@Override」語句:D – Siggy1000 2013-03-23 15:42:51

1

當屏幕正在成爲當前屏幕show方法被調用(不創建一個像你的情況),請嘗試更改您的創建方法來顯示

還您是init階段錯了,你應該把它的寬度和高度,你送0,0 嘗試像

stage = new Stage(Gdx.graphics.getWidth(),Gdx.graphics.getHeight(),false); 
+0

黑屏以及...這是不是解決辦法:/ – Siggy1000 2013-03-21 20:16:41

+0

盡我編輯的答案,也確保節目被稱爲 – idanakav 2013-03-21 20:35:54

+0

它也沒有工作。最後一個布爾值是「拉伸」的布爾值,所以它沒關係,我先輸入的內容,它總是被拉伸到屏幕大小... – Siggy1000 2013-03-21 20:54:49