在libgdx中确定来自平底锅的投掷

时间:2016-06-02 05:31:58

标签: libgdx gestures pan onfling

我正在使用LibGDX开发游戏,而且我无法从fling确定pan

我的GestureListener

@Override
public boolean fling(float velocityX, float velocityY, int button) {
    //if (velocityX > 1000f) {
    // I can use this to exclude slow pans from the executing a fling
        System.out.println("Flinged - velocityX: " + velocityX + ", button: " + button);
    //}
    return false;
}

@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
    // but there doesn't seem to be a way to have this not fire on a fling
    System.out.println("Panned - deltaX: " + deltaX);
    return false;
}

@Override
public boolean panStop(float x, float y, int pointer, int button) {
    System.out.println("Pan Stop - pointer: " + pointer + ", button: " + button);
    return false;
}

问题在于panfling都会触发。我理解fling基本上是快pan,但我需要能够在两个手势之间确定,以便我可以分别处理每个手势。

简明扼要的问题是,如何为flingpan提供独特的操作?

1 个答案:

答案 0 :(得分:0)

在我看来,最合理的解决方案是使用longPress设置一些布尔标志以进入平移模式'在没有长按的情况下滑动只是为了甩动。

我就是这样看的:

    //the flag for checking if pan mode entered
    boolean PAN = false;

    @Override
    public boolean longPress(float x, float y) {
        PAN = true;
        return false;
    }

    @Override
    public boolean fling(float velocityX, float velocityY, int button) {
        if(!PAN) {
            System.out.println("Flinged - velocityX: " + velocityX + ", button: " + button);
        }
        return false;
    }

    @Override
    public boolean pan(float x, float y, float deltaX, float deltaY) {
        if(PAN) {
            System.out.println("Panned - deltaX: " + deltaX);
        }
        return false;
    }

    @Override
    public boolean panStop(float x, float y, int pointer, int button) {
        if(PAN) {
            PAN = false;
            System.out.println("Pan Stop - pointer: " + pointer + ", button: " + button); 
        }
        return false;
    }

当然,如果longPress太长,您可以使用GestureDetector实例的setLongPressSeconds(float longPressSeconds)方法进行更改