How can I create LibGDX button and set touch listener to it?I want to create main menu of my game and put three buttons there (play,settings,about).I tried to do that with Sprite but how I saw Sprite doesnt have touch listener.
asked May 31, 2014 at 6:13
Vahe Muradyan
1,1151 gold badge11 silver badges22 bronze badges
1 Answer 1
You can use Stage and Button class, something like this:
Button btn = new Button(new SpriteDrawable(yourIdleSprite),
new SpriteDrawable(yourPressedSprite));
btn.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
//your code
}
});
Stage stage= new Stage();
stage.addActor(btn);
There also lots of ways to create your own button class, you can also find a lot of examples in official documentation -> https://github.com/libgdx/libgdx/wiki
answered May 31, 2014 at 21:00
Alon Zilberman
2,1551 gold badge16 silver badges16 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Vahe Muradyan
I have tried in that way but click listener dont work((
Alon Zilberman
post your code here, maybe I will able to help. Also maybe you didn't set inputProcessor? Like this: Gdx.input.setInputProcessor(stage); - you should set inputProcessor in order to handle clicks.
default