LibGDX Scene2d.ui仅显示带有以下代码的白色屏幕

时间:2014-11-23 21:47:54

标签: java libgdx scene2d

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测试。

我非常困惑为什么没有出现文本按钮。任何帮助将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:2)

尝试不设置Table的范围,而是使用table.setFillParent(true)。此外,您需要以下列方式实施resize(...)

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