当手指消失时如何获得事件

时间:2013-08-07 07:59:03

标签: javascript leap-motion

我正在申请leap motion

我可以检测到手指何时进入传感器,但我无法检测到所有手指何时消失。

有没有办法告诉所有手指像鼠标鼠标输出一样消失?

1 个答案:

答案 0 :(得分:1)

当指针对象(手指或工具)消失时没有事件,但要处理此事件,您可以保留前一帧或有关前一帧的信息,并检查手指是否在设备区域中。

var lastNbFingers = 0;

// Setup Leap loop with frame callback function
var controllerOptions = {enableGestures: true};
Leap.loop(controllerOptions, function(frame)
{
  var nbFingers = 0; // Cpt for all fingers from all hands in the current frame
  var fingerRemoved = false; // are all the fingers just removed from device area ?

  // how many fingers in our scene
  for (var h = 0; h < frame.hands.length; ++h)
  {
    var hand = frame.hands[h];
    nbFingers += hand.fingers.length;
  }

  if (nbFingers > 0)   // there are fingers
    lastNbFingers = nbFingers;
  else if (lastNbFingers > 0)  // there is no finger on current frame, but some on previous frame
    {
      lastNbFingers = 0;
      fingerRemoved = true;   
    }
   if (fingerRemoved)
      // do some stuff

});