【发布时间】:2016-05-30 15:53:25
【问题描述】:
我对 LibGDX 有点陌生,想知道如何控制一次可以有多少个按钮处于关闭状态。我想用这些按钮完成的想法是:只要我的手指碰到一个,它就会被按下,一次只能按下一个,如果我的一个手指在一个按钮上按下它,另一个手指按下另一个按钮,最初按下的按钮会返回到其向上状态,再次按下该按钮的唯一方法是松开手指并再次按下它。
无论如何,这是我的代码。任何帮助将不胜感激,谢谢。
public MenuStateTest(GameStateManager gsm) {
super(gsm);
cam.setToOrtho(false, MyGame.WIDTH, MyGame.HEIGHT);
fitViewport = new FitViewport(MyGame.WIDTH, MyGame.HEIGHT);
stage = new Stage(fitViewport);
Gdx.input.setInputProcessor(stage);
font = new BitmapFont();
skin = new Skin();
buttonAtlas = new TextureAtlas("buttonTest.pack");
skin.addRegions(buttonAtlas);
textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("1BBlock");
textButtonStyle.down = skin.getDrawable("T1BBlock");
button = new TextButton("", textButtonStyle);
stage.addActor(button);
button.setPosition(20, 200);
button.getStyle().checked = button.getStyle().down;
button2Atlas = new TextureAtlas("Button2Test.pack");
skin.addRegions(button2Atlas);
textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("2BBlock");
textButtonStyle.down = skin.getDrawable("T2BBlock");
button2 = new TextButton("", textButtonStyle);
stage.addActor(button2);
button2.setPosition(175, 200);
button2.getStyle().checked = button2.getStyle().down;
button3Atlas = new TextureAtlas("Button3Test.pack");
skin.addRegions(button3Atlas);
textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("3BBlock");
textButtonStyle.down = skin.getDrawable("T3BBlock");
button3 = new TextButton("", textButtonStyle);
stage.addActor(button3);
button3.setPosition(330, 200);
button3.getStyle().checked = button3.getStyle().down;
ButtonGroup buttons = new ButtonGroup(button1, button2, button3);
buttons.setMaxCheckCount(1);
}
@Override
protected void handleInput() {
}
@Override
protected void update(float dt) {
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
【问题讨论】:
标签: java android button libgdx