2015-04-01 47 views
0

我想在我的函数中处理事件。所以它在我的gameLogic函数中为每种类型的事件做了一些事情。TouchSwipe所有事件

虽然,在TAP没有得到认可......

我应该怎么办?我应该分开每个事件吗?

$(function() { 
    $(".main-wrapper-inner").swipe({ 
     //Generic swipe handler for all directions 
     tap:function(event, target) { 
      gameLogic("tap"); 
     }, 
     swipeLeft:function(event, distance, duration, fingerCount, fingerData) { 
      gameLogic("swipeLeft"); 
     }, 
     swipeRight:function(event, distance, duration, fingerCount, fingerData) { 
      gameLogic("swipeRight"); 
     }, 
     swipeUp:function(event, distance, duration, fingerCount, fingerData) { 
      gameLogic("swipeUp"); 
     }, 
     swipeDown:function(event, distance, duration, fingerCount, fingerData) { 
      gameLogic("swipeDown"); 
     }, 

     pinchIn:function(event, direction, distance, duration, fingerCount, pinchZoom, fingerData) { 
      gameLogic("pinchIn"); 
     }, 
     pinchOut:function(event, direction, distance, duration, fingerCount, pinchZoom, fingerData) { 
      gameLogic("pinchOut"); 
     }, 

     threshold:0, 
     fingers: 'all' 
    }); 
}); 

回答

0

您可以获取刷卡方向(但不是捏方向),这样就可以减少很多的代码(见下文)。

关于水龙头,您不得在内部设置threshold: 0,以禁用所有水龙头/点击事件。将threshold设置为高于0的任何值,或完全省略(默认为75)以使水龙头功能生效

$(function() { 
    $(".main-wrapper-inner").swipe({ 
     //Generic swipe handler for all directions 
     tap:function(event, target) { 
      gameLogic("tap"); 
     }, 
     swipe(event, direction) { 
      // You can obtain the swipe direction 
      // and process it in your game logic 
      gameLogic("swipe", direction); 
     } 
     pinchIn:function(event) { 
      gameLogic("pinchIn"); 
     }, 
     pinchOut:function(event) { 
      gameLogic("pinchOut"); 
     }, 
     threshold: 75, // This must NOT be 0 for taps to work 
     fingers: 'all' 
    }); 
});