When my splash screen has faded in and then out I'm doing this:
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu(game));
But I get a black screen.
This is the Splash Screen:
public class SplashScreen implements Screen {
private SpriteBatch batch;
private Sprite splash;
private TweenManager tweenManager;
private static RunningGame game;
public SplashScreen(RunningGame g) {
game = g;
}
@Override
public void show() {
batch = new SpriteBatch();
tweenManager = new TweenManager();
Tween.registerAccessor(Sprite.class, new SpriteAccessor());
splash = new Sprite(new Texture("splash.png"));
Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
Tween.to(splash, SpriteAccessor.ALPHA, 1.5f).target(1).repeatYoyo(1, .5f).setCallback(new TweenCallback() {
@Override
public void onEvent(int type, BaseTween<?> source) {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu(game));
}
}).start(tweenManager);
tweenManager.update(Float.MIN_VALUE);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
splash.draw(batch);
batch.end();
tweenManager.update(delta);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
dispose();
}
@Override
public void dispose() {
batch.dispose();
splash.getTexture().dispose();
}
}
This is the Main Menu Screen that's not showing up:
public class MainMenu implements Screen {
private Stage stage;
private Skin skin;
private Table table;
private static RunningGame game;
public MainMenu(RunningGame g) {
game = g;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
table.invalidateHierarchy();
}
@Override
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), new TextureAtlas("ui/atlas.pack"));
table = new Table(skin);
table.setFillParent(true);
TextButton buttonPlay = new TextButton("PLAY", skin, "big");
buttonPlay.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
stage.addAction(sequence(moveTo(0, -stage.getHeight(), .5f), run(new Runnable() {
@Override
public void run() {
((Game) Gdx.app.getApplicationListener()).setScreen(new PlayScreen(MainMenu.game));
}
})));
}
});
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
}
}
In case the JSON file is the error:
{
"com.badlogic.gdx.graphics.Color": {
"white": { "r": 1, "g": 1, "b": 1, "a": 1 },
"black": { "r": 0, "g": 0, "b": 0, "a": 1 },
"gray": { "r": 0.3, "g": 0.3, "b": 0.3, "a": 1 },
"red": { "r": 1, "g": 0, "b": 0, "a": 1 },
"green": { "r": 0, "g": 1, "b": 0, "a": 1 },
"blue": { "r": 0, "g": 0, "b": 1, "a": 1 }
},
"com.badlogic.gdx.graphics.g2d.BitmapFont": {
"white64": { "file": "font/white64.fnt" },
"black64": { "file": "font/black64.fnt" },
"white32": { "file": "font/white32.fnt" },
"black32": { "file": "font/black32.fnt" },
"white16": { "file": "font/white16.fnt" },
"black16": { "file": "font/black16.fnt" }
},
"com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
"default": { "font": "white32", "fontColor": "white" },
"big": { "font": "white64", "fontColor": "white" },
"small": { "font": "white16", "fontColor": "white" }
},
"com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
"default": { "up": "button.up", "down": "button.down", "font": "black32", "pressedOffsetX": 1, "pressedOffsetY": -1 },
"big": { "up": "button.up", "down": "button.down", "font": "black64", "pressedOffsetX": 1, "pressedOffsetY": -1 },
"small": { "up": "button.up", "down": "button.down", "font": "black16", "pressedOffsetX": 1, "pressedOffsetY": -1 }
},
"com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle": {
"default": { "font": "white32", "fontColorUnselected": "white", "fontColorSelected": "black", "selection": "default.selection" }
},
"com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle": {
"default": { "hScrollKnob": "button.up", "vScrollKnob": "button.up" }
},
"com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle": {
"default": { "font": "white32", "checkboxOn": "checkbox.on", "checkboxOff": "checkbox.off", "checkboxOver": "checkbox.over" }
},
"com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle": {
"default": { "font": "black32", "fontColor": "black", "messageFontColor": "gray", "background": "default.background", "cursor": "default.selection" }
}
}
Like Tenfour04 already stated, you created a stage, and did not add anything to it. Also you did not set the button position.
If you want the button inside the table:
//Setting table bounds
table.setBounds(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
//Adding button to table
table.add(buttonPlay).width(20).height(20);
// Adding table to stage
stage.addActor(table);
If you want the button outside the table(table is not needed):
//Setting button size
buttonPlay.setSize(80,80);
//Setting button position
buttonPlay.setPosition(Gdx.graphics.getWidth()/2 - buttonPlay.getWidth()/2,10);
// Adding button to stage
stage.addActor(buttonPlay);