2014-11-23 82 views
0
package com.Darth377Apps.DeepShadow; 

import com.badlogic.gdx.*; 
import com.badlogic.gdx.graphics.g2d.*; 
import com.badlogic.gdx.scenes.scene2d.*; 
import com.badlogic.gdx.scenes.scene2d.ui.*; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; 
import com.badlogic.gdx.graphics.*; 
import com.badlogic.gdx.utils.viewport.*; 

public class MainMenu implements Screen 
{ 

private Stage stage; 
private Table table; 
private TextureAtlas atlas; 
private TextButton buttonPlay, buttonExit; 
private Label heading; 
private BitmapFont white; 
private Skin skin; 
private TextButton TextButton; 
@Override 
public void create(){ 
    stage = new Stage(new ScreenViewport()); 
    Gdx.input.setInputProcessor(stage); 


    atlas = new TextureAtlas("ui/button.pack"); 
    skin= new Skin(atlas); 
    table=new Table(skin); 
    table.setBounds(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight()); 
    white= new BitmapFont(Gdx.files.internal("Font/white.fnt"),false); 
    TextButtonStyle textButtonStyle = new TextButtonStyle(); 
    textButtonStyle.up = skin.getDrawable("button.up.9"); 
    textButtonStyle.down = skin.getDrawable("button.down.9"); 
    textButtonStyle.pressedOffsetX = 1; 
    textButtonStyle.pressedOffsetY = -1; 
    textButtonStyle.font = white; 
    textButtonStyle.fontColor = Color.BLACK; 

    buttonExit = new TextButton("EXIT",textButtonStyle); 
    buttonExit.pad(20); 

    table.add(buttonExit); 
    stage.addActor(table); 
} 

@Override 
public void render(float p1) 
{ 
    Gdx.gl.glClearColor(0,0,0,1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 


    stage.act(p1); 
    stage.draw(); 
} 

@Override 
public void resize(int p1, int p2) 
{ 
    // TODO: Implement this method 
} 

@Override 
public void show(){ 


} 
@Override 
public void hide() 
{ 

} 

@Override 
public void pause() 
{ 
    // TODO: Implement this method 
} 

@Override 
public void resume() 
{ 
    // TODO: Implement this method 
} 

@Override 
public void dispose() 
{ 
    // TODO: Implement this method 
} 

} 

當我運行該應用程序時,只出現一個白色屏幕。該應用程序肯定會運行此代碼,因爲我已通過logcat進行測試。LibGDX Scene2d.ui只顯示以下代碼的白色屏幕

我非常困惑,爲什麼沒有出現文本按鈕。任何幫助將不勝感激。謝謝。

回答

2

嘗試不設置Table的界限,而是使用table.setFillParent(true)來代替。此外,您需要按以下方式實施resize(...)

public void resize(int p1, int p2) 
{ 
    stage.getViewport().update(p1, p2, true); 
}