我正在尝试使用scene2D显示菜单UI的简单文本,但由于某种原因,此处未显示任何内容。屏幕显示纯黑色。
public class ScreenMenu implements Screen {
MyGame myGame;
SpriteBatch batch;
Stage stage;
Label labelNewGame, labelContinue, labelCredits;
public ScreenMenu(MyGame myGame) {
this.myGame = myGame;
}
@Override
public void show() {
init();
BitmapFont font = initFont();
initLabels(font);
initStage();
}
private void init() {
batch = new SpriteBatch();
}
private BitmapFont initFont() {
return new FontLoader().getMichroma();
}
private void initLabels(BitmapFont font) {
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
labelNewGame = new Label("New Game", labelStyle);
labelContinue = new Label("Continue", labelStyle);
labelCredits = new Label("Credits", labelStyle);
}
private void initStage() {
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
stage.addActor(labelNewGame);
}
@Override
public void render(float delta) {
GlHelper.clearScreen();
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
dispose();
}
@Override
public void dispose() {
myGame.dispose();
batch.dispose();
stage.dispose();
}
}
以下类包含clearScreen
函数。如果我没有运行它,整个屏幕就变得超级毛躁,但我可以看到New Game文字。
public class GlHelper {
public static void clearScreen() {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
public static void clearScreen(float red, float green, float blue, float alpha) {
Gdx.gl.glClearColor(red, green, blue, alpha);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
}
答案 0 :(得分:0)
setBounds(x,y,w,h);
之前添加阶段例如:
labelNewGame.setBounds(0, 0, 100, 100);
也许他可以帮助你。
答案 1 :(得分:0)
我现在感到愚蠢。在FontLoader
实现中,我将FreeTypeFontParameter
颜色设置为Color.BLACK
。显然它覆盖了Color.WHITE
的{{1}}参数。