libgdx中按钮的touchUpInside和touchUpOutside



LibGDX提供了事件监听器,我们可以将其附加到按钮上。侦听器内部有一个方法touchUp(),我们可以覆盖它。我来自iOS开发,在iOS中有一个选项touchUpInsidetouchUpOutside。即,如果用户在按钮区域内释放手指,则调用touchUpInside,并且如果用户在该按钮区域外抬起手指,则呼叫touchUpOutside。libGDX是否提供类似的功能,或者由开发人员来实现?默认的libgdx touchUp不会区分这些场景。

edit:我使用了这段代码,但这非常不精确。我收到了很多虚假的触摸Up的

public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                super.touchUp(event, x, y, pointer, button);
            if(x<button.getX()||x>(button.getX()+button.getWidth())||y<button.getY()||y>(button.getY()+button.getHeight())){
                System.out.println("retuuurn");
                return;
            }
}

这是有效的:

if(x<button.getOriginX()-button.getWidth()*0.5f||x>(button.getOriginX()+button.getWidth()*0.5f)||y<button.getOriginY() - button.getHeight()*0.5f||y>(button.getOriginY()+button.getHeight()*0.5f)){
//do stuff
}

最新更新