gpt4 book ai didi

java - 关闭背景图像触摸 libgdx 上的对话框

转载 作者:行者123 更新时间:2023-11-30 00:38:36 25 4
gpt4 key购买 nike

我试图在背景触摸时关闭一个对话框,但它总是处于 else 状态

stage.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if(stage.hit(x,y,true).equals(bg)) {
System.out.println("in th if");
dialog.addAction(rotateTo(90, .30f, Interpolation.smooth2));
dialog.hide();
}
else {
System.out.println("int the else");
}
return true;
}

});

最佳答案

我认为这会起作用,但没有测试。

Dialog 已经设置为在可见时接收所有 touchDown 输入,即使触摸超出其边界,因此只需为其提供一个监听器,如果触摸超出其边界则隐藏它:

    dialog.addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
if (x < 0 || x > dialog.getWidth() || y < 0 || y > dialog.getHeight()){
dialog.hide();
}
return true;
}
});

这假设 dialog 是最终字段或成员字段,因此您可以从监听器访问它。

我认为您的代码不起作用的原因是 stage.hit(...) 将始终返回 dialog 而不管坐标,因为已设置对话框吸收所有输入。

关于java - 关闭背景图像触摸 libgdx 上的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42952461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com