I'm trying to draw two buttons but I'm having problems with stage.
ModeGameView(ScreenAdapter next_screen) {
super(next_screen);
atlas = new TextureAtlas("buttons.txt");
background = atlas.createSprite("background");
title = atlas.createSprite("cluedo");
title.scale((float) 1);
size = (title.getHeight() + 100);
singleplayer = atlas.createSprite("singleplayer");
singleplayer.setCenterX(500);
multiplayer = atlas.createSprite("multiplayer");
batch = new SpriteBatch();
camera = new OrthographicCamera();
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
viewport.apply();
camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
camera.update();
stage = new Stage();
}
@Override
public ScreenAdapter renderAndUpdate(float delta) {
this.render(delta);
return this;
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
Drawable playDrawable = new SpriteDrawable(singleplayer);
singleplayerButton = new ImageButton(playDrawable);
Drawable exitDrawable = new SpriteDrawable(multiplayer);
multiplayerButton = new ImageButton(exitDrawable);
singleplayerButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Cluedo.getInstance().setCurrentState(new SinglePlayerView(Cluedo.getInstance().getGameView()));
}
});
multiplayerButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Cluedo.getInstance().setCurrentState(new MultiplayerView(Cluedo.getInstance().getGameView()));
}
});
stage.addActor(singleplayerButton);
stage.addActor(multiplayerButton);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(.1f, .12f, .16f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
background.draw(batch);
title.setPosition((Gdx.graphics.getWidth() - title.getWidth()) / 2, Gdx.graphics.getHeight() - size);
title.draw(batch);
batch.end();
stage.setDebugAll(true);
stage.act();
stage.draw();
}
When I try stage.draw() it doesn't draw nothing. I create two sprites and then I create the buttons. In the render the backgroun and the title drawing works but the stage not.
I don't know what to do now, help me!!!
尝试在舞台构造器上设置视口,并设置可绘制对象的位置。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.