首页 文章

如何使跳跃动作不检测滑动手势

提问于
浏览
0

我只想检测滑动手势方向“上/下”和“右/左” . 当我向前伸展双手时,飞跃运动不应该检测到该动作以轻扫手势 . 我该怎么做?

String swipeDirection;

    GestureList gestures = frame.gestures();
    for(int i=0; i<gestures.count(); i++){
        Gesture gesture = gestures.get(i);

        if(gesture.type()==gesture.type().TYPE_SWIPE){
            SwipeGesture swipeGesture = new SwipeGesture(gesture);
            boolean isHorizontal = Math.abs(swipeGesture.direction().get(0))>Math.abs(swipeGesture.direction().get(1));
            if(isHorizontal){
                if(swipeGesture.direction().get(0)>0){
                    swipeDirection = "right";
                }else{
                    swipeDirection="left";
                }
            }else{
                if(swipeGesture.direction().get(1)>0){
                    swipeDirection="up";
                }else{
                    swipeDirection = "down";
                }
            }
            System.out.println("direction: "+swipeDirection + " hand: "+frame.hands().get(0).isLeft()
                    +", duration: "+swipeGesture.durationSeconds());
        }
    }
}
}

1 回答

  • 0

    您希望确保方向指向x轴或y轴而不是z轴 . 因此,与计算滑动方向是否水平的方式类似,您需要检查它是否向前/向后:

    boolean isNotForward = Math.abs(swipeGesture.direction().get(0)) >
                           Math.abs(swipeGesture.direction().get(2)) || 
                           Math.abs(swipeGesture.direction().get(1)) >
                           Math.abs(swipeGesture.direction().get(2));
    

相关问题