有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java以编程方式单击场景2D LibGDX中的按钮

每当我按下按钮2时,我想通过编程方式点击按钮1(点击按钮2后,按钮1在clicklistener中显示style.down然后显示style.up和do函数)。我在that帖子上发现了类似的问题,但对我不起作用

在安卓中,我只需调用performAction()方法,但我无法使用LibGDX库找到类似的方法


共 (1) 个答案

  1. # 1 楼答案

    我想:

    解决方案(受this帖子启发)

    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();
    
                }
            });