我目前正在尝试实现一个clickListener。我在运行时找到了一个很好的工具,名为Overlap2D,在那里我制作了一些很好的按钮并加载了它们,一切都很好。因为我想为我的按钮设置一个“悬停”效果,所以我使用了ClickListener和方法enter和exit,它看起来是这样的:
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor){
playButton.setLayerVisibility("MouseOver", true);
playButton.setLayerVisibility("pressed", false);
playButton.setLayerVisibility("normal", false);
System.out.println("Actor enter : "+fromActor);
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor){
playButton.setLayerVisibility("MouseOver", false);
playButton.setLayerVisibility("pressed", false);
playButton.setLayerVisibility("normal", true);
System.out.println("Actor exit : "+toActor);
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button){
System.out.println("touchdown");
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button){
System.out.println("touchup");
}这里的问题是,触地和触地被称为一次,当我按下按钮或向上。但是,enter和exit方法在触地得分和touchupo事件O中也会被调用,看起来是这样的:
touchdown
Actor enter : null
Actor exit : Image
Actor enter : Image
touchup
Actor exit : Image
Actor exit : Image
Actor enter : Image
Actor exit : Image
Actor enter : Image我还打印了用于调试^^的fromActor和toActor,但我仍然不知道为什么它会触发出口和输入事件。有人有主意吗?
谢谢:)
发布于 2016-03-31 15:35:40
您需要检查传递给enter和exit方法的exit。如果pointer为-1,则鼠标光标刚刚启动或停止悬停在参与者的边界上。它的pointer不是-1,然后演员只收到一个点击向下或点击发布(分别为enter和exit )。
因此,如果您将光标移动到按钮上,然后单击然后移开,您将得到两个enter事件和两个exit事件。
此外,在使用ClickListener时,确保在重写方法时调用超级方法,这样它就会正常运行!
https://stackoverflow.com/questions/36336111
复制相似问题