我在Stage
上有一个Label
演员,我一辈子都无法获得输入,即 touchDown
和touchUp
事件被触发。
在我的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
过。
无论如何,让它工作,终于=]]