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
}
}
When I run the app, only a white screen appears. The app definitely runs this code, as I ha e tested through logcat.
I am extremely confused as to why the text button does not appear. Any help would be greatly appreciated. Thank you.
Try to not set the bounds of the
Table, but to usetable.setFillParent(true)instead. Furthermore you need to implementresize(...)in the following way: