我希望在InputListener中使用exit()方法来判断光标是否在按钮内。
以下是libGDX文档中的解释。
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
每当鼠标光标或手指触摸移出演员时调用。
但是,当我把光标放在按钮上,然后将其移动到按钮外时,该方法不会被调用。我通过
System.out.println("exited");
进行测试,控制台没有任何输出。编辑:
LibGDX 版本:最新稳定版夜间版本
InputListener 实现:
//This button class is a custom class to make button creation easier. This is the constructor.
public Button(Vector2 position, String packLocation, String text, Stage stage, BitmapFont font, Color color) {
//Removed buttonStyle creation etc. to shorten the code.
button = new TextButton(text, buttonStyle);
button.setPosition(position.x, position.y);
stage.addActor(button);
Gdx.input.setInputProcessor(stage);
pressed = false;
button.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
pressed = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
pressed = false;
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
System.out.println("exited");
}
});
}
编辑:
悬停在按钮上也不会改变按钮的纹理,因为我已经设置了如下内容:
buttonStyle.over = skin.getDrawable("over");
但是点击会改变。