我正在尝试在 LibGDX 中制作菜单。但是我无法在屏幕上绘制 Button 或 textButton 。我尝试使用测试皮肤。我试着用一张桌子。我尝试使用按钮和文本按钮。
图像很好,因为它可以在使用 SpriteBatch 绘制时出现,而且字体也很好用。
这是我的代码的一部分。
public class Menu implements Screen {
private Stage stage;
private Skin skin;
private TextButton textButton;
private Game mygame;
private BitmapFont font;
private TextureAtlas atlas;
private SpriteBatch batch;
private TextureRegion test;
public SplashScreen(Game g){
mygame = g;
}
@Override
public void show() {
batch = new SpriteBatch();
stage = new Stage();
stage.clear();
atlas = new TextureAtlas("buttons/bot.pack");
skin = new Skin(atlas);
font = new BitmapFont(Gdx.files.internal("fonts/arialfnt.fnt"),false);
TextButtonStyle buttonStyle = new TextButtonStyle();
buttonStyle.up = skin.getDrawable("button.up");
buttonStyle.over = skin.getDrawable("button.over");
buttonStyle.down = skin.getDrawable("button.down");
buttonStyle.font = font;
textButton = new TextButton("Click here", buttonStyle);
textButton.setPosition(200, 300);
textButton.setHeight(300);
textButton.setWidth(100);
test = atlas.findRegion("button.up"); //Testing the atlas
stage.addActor(textButton);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw(); //DOES NOT WORK
batch.begin();
batch.draw(test, 300, 300); //It works
font.draw(batch, "BLA BLA!", 50, 500); //It works
batch.end();
}
}
你有什么建议来完成这项工作吗?难道是因为GL3.0?