【问题标题】:touchUpInside and touchUpOutside of a button in libgdxlibgdx 中按钮的 touchUpInside 和 touchUpOutside
【发布时间】:2015-12-25 18:43:09
【问题描述】:

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

编辑:我使用了这段代码,但这非常不精确。我得到了很多错误的修饰

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;
            }
}

【问题讨论】:

  • 是的,你需要自己实现。

标签: libgdx touch-up-inside


【解决方案1】:

这行得通:

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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 2018-01-12
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多