简体   繁体   English

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

[英]Determining a fling from a pan in libgdx

I'm developing a game with LibGDX and I'm having trouble determining a fling from a pan . 我正在开发与LibGDX一个游戏,我无法确定flingpan

My GestureListener : 我的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;
}

The problem is that if both pan and fling fire. 问题是,如果panfling发生火灾。 I understand that a fling is basically a fast pan , but I need to be able to determine between the two gestures so I can handle each one separately. 我知道fling基本上是一个快速的pan ,但我需要能够确定两个手势之间,以便我可以分别处理每个手势。

A succinct way of asking is, how do I provide unique actions for fling and pan ? 一个简洁的问题是,我如何为flingpan提供独特的操作?

The most reasonable solution for this in my opinion is to use longPress to set some boolean flag to 'enter the panning mode' when swiping without long press will only be about making fling. 在我看来,最合理的解决方案是使用longPress将一些布尔标志设置为“进入平移模式”,而在不长按的情况下滑动将仅仅是为了进行投掷。

This is how I see this: 这就是我看到的:

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

Of course if the longPress is too long for your purposes you can change it by using setLongPressSeconds(float longPressSeconds) method of the GestureDetector instance 当然,如果longPress太长,你的目的,你可以使用改setLongPressSeconds(float longPressSeconds)的方法GestureDetector实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM