我有一個帶有SpriteBatch的GameScreen來繪製我所有的紋理,但是我現在想在畫面上添加一個暫停按鈕。我試圖在我的SpriteBatch之上使用舞臺,但由於某種原因,它不會顯示出來。Hud的階段不可見
下面是一些代碼:
構造:
public GameScreen(MyGame game) {
stage = new Stage();
table = new Table();
pause_texture = new Texture("path_to_texture.png");
pause_image = new Image(pause_texture);
pause_image.setPosition(1920 - pause_image.getWidth() - 20, 20);
table.add(pause_image);
stage.addActor(table);
}
渲染方法:
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
game.camera.update();
game.batch.setProjectionMatrix(game.camera.combined);
game.batch.begin();
//rendering stuff here
game.batch.end();
}
我在做什麼錯?
你的setPosition pause_button.getWidth()的值是什麼?不應該是pause_image.getWidth()? – Hllink
哦,是的,它應該是pause_image.getWidth(),我有我的代碼。 –