当我的启动画面渐渐消失然后我正在执行此操作时
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu(game));
但是我得到了黑屏。
这是启动画面:
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();
}
}
这是未显示的主菜单屏幕:
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();
}
}
如果JSON文件是错误:
{
"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" }
}
}
答案 0 :(得分:2)
就像已经说过的Tenfour04一样,你创建了一个舞台,并没有添加任何东西。您也没有设置按钮位置。
如果你想要表格中的按钮:
//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);
如果您想要表格外的按钮(不需要表格):
//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);