处理标签执行组件的输入



我在Stage上有一个Label演员,我一辈子都无法获得输入,即 touchDowntouchUp事件被触发。

在我的show()方法中,我也有这个: Gdx.input.setInputProcessor(mainMenuStage);

初始化Label并设置其位置和边界,然后我向Label添加一个EventListener,如下所示:

myLabel.addListener(new InputListener(){
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            super.touchDown(event, x, y, pointer, button);
            System.out.println("touchdown");
            return true;
        }
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            System.out.println("touchup");
        }
    });

一旦Label全部设置完毕,我就会将其添加到Stage

但是当我点击myLabel时,LogCat/Console中没有打印任何内容.

我太愚蠢了! -.-

甚至在我开始mainMenuStage之前就打电话给Gdx.input.setInputProcessor(mainMenuStage);。有趣的是,我从来没有NullReferenceException过。

无论如何,让它工作,终于=]]

最新更新