Libgdx以不同的方式进行手势检测

时间:2015-11-24 09:19:05

标签: libgdx

在我的游戏中,我实现了手势检测。一切正常,但我想修改fling检测

来自fling的文档:https://github.com/libgdx/libgdx/wiki/Gesture-detection

fling: A user dragged the finger across the screen, then lifted it. Useful to implement swipe gestures.

我想修改这个并且不用提升触摸就可以工作,只有当用户拖动一段距离而不抬起它时。

这是我的代码:

public class SimpleDirectionGestureDetector extends GestureDetector {


    public interface DirectionListener {
        void onLeft();

        void onRight();

        void onUp();

        void onDown();
    }

    public SimpleDirectionGestureDetector(DirectionListener directionListener) {
        super(new DirectionGestureListener(directionListener));
    }

    private static class DirectionGestureListener extends GestureAdapter{
        DirectionListener directionListener;

        public DirectionGestureListener(DirectionListener directionListener){
            this.directionListener = directionListener;
        }

        @Override
        public boolean fling(float velocityX, float velocityY, int button) {
            if(Math.abs(velocityX)>Math.abs(velocityY)){
                if(velocityX>0){
                    directionListener.onRight();
                }else{
                    directionListener.onLeft();
                }
            }else{
                if(velocityY>0){
                    directionListener.onDown();
                }else{
                    directionListener.onUp();
                }
            }
            return super.fling(velocityX, velocityY, button);
        }

    }

}


   public SimpleDirectionGestureDetector gestureDetector = new SimpleDirectionGestureDetector(
        new SimpleDirectionGestureDetector.DirectionListener() {

            @Override
            public void onUp() {
                onUpSwipe();
            }

            @Override
            public void onRight() {
                onRightSwipe();
            }

            @Override
            public void onLeft() {
                onLeftSwipe();
            }

            @Override
            public void onDown() {
                onDownSwipe();
            }

        });

任何帮助将不胜感激

由于

0 个答案:

没有答案