Expiredmind
Expiredmind

Reputation: 808

Programically click on the button in scene 2D LibGDX

I want to programically click on the button1 whenever I pressed on button2 (after clicked on button2 the button1 show style.down then style.up and do function in the clicklistener). I found similiar issue on that post but doesnt work for me.

In android I just have to call the performAction() method, but I couldnt find similiar method using LibGDX Library

Upvotes: 1

Views: 379

Answers (1)

Expiredmind
Expiredmind

Reputation: 808

I figure it out :

The solution (Inspired by this post)

button2.addListener(new ClickListener(){
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                InputEvent event1 = new InputEvent();
                event1.setType(InputEvent.Type.touchDown);
                button1.fire(event1);
            return true;
            }
            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

                InputEvent event2 = new InputEvent();
                event2.setType(InputEvent.Type.touchUp);
                button1.fire(event2);
              doSmth();

            }
        });

Upvotes: 1

Related Questions