public class GameScreen implements Screen {
public void show()
{
buttonsAtlas = new TextureAtlas("Color.pack"); //button atlas image
buttonSkin = new Skin();
buttonSkin.addRegions(buttonsAtlas);
font = new BitmapFont(Gdx.files.internal("CustomFont.fnt"), false); //the font
stage = new Stage(); // window is stage
stage.clear();
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); // button properties
style.up = buttonSkin.getDrawable("Red");
style.down = buttonSkin.getDrawable("Blue");
style.font = font;
gameButton = new TextButton("Game Screen", style); //button text and style
gameButton.setPosition(-250, 500); //button location
gameButton.setHeight(600); //button height
gameButton.setWidth(1200); //button width
shopButton = new TextButton("Shop Menuuuu", style); //button text and style
shopButton.setPosition(100, 500); //button location
shopButton.setHeight(600); //button height
shopButton.setWidth(1200); //button width
stage.addActor(shopButton);
stage.addActor(gameButton);
Gdx.input.setInputProcessor(stage);
gameButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
gameButton.setBounds(-250, 500, 100, 100);
Gdx.app.log("my app,", "pressed");
game.setScreen(new inGame(game));
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("my app", "released");
}
});
shopButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
shopButton.setBounds(100, 500, 100, 100);
Gdx.app.log("my app,", "pressed");
game.setScreen(new Shop(game));
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("my app", "released");
}
});
}
public void render(float x)
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
game.batch.begin();
stage.draw();
game.batch.end();
}
public void dispose()
{
batch.dispose();
buttonSkin.dispose();
buttonsAtlas.dispose();
stage.dispose();
}
ich zu machen zwei TextButton
s versuche zugleich zu arbeiten. Es wird jedoch immer eine Schaltfläche auf dem Bildschirm angezeigt, die letzte Schaltfläche, die der Bühne hinzugefügt wurde. In diesem Fall ist es die gameButton
, weil es die letzte Schaltfläche ist, die der Bühne hinzugefügt wurde.Zwei verschiedene TEXTBUTTON reagieren nicht auf Libgdx
Wie mache ich beide Tasten funktionieren?
Ihr Code funktioniert gut, ich nehme an, dass das Problem mit der Größe der Tasten ist. Warum sind die Breite und Höhe der Schaltflächen so groß? – Enigo