0

I am trying to handle the events in my function. So it does something in my gameLogic function for each type of event.

Although, the TAP doesn't get recognized ...

What should I do ? Should i separate each event ?

$(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'
    });
});
Shaunak D
  • 20,588
  • 10
  • 46
  • 79
Kiwimoisi
  • 4,086
  • 6
  • 33
  • 64

1 Answers1

0

You can obtain the swipe direction (but not pinch direction), so you can reduce a lot of your code (see below).

Regarding tap, you must not set threshold: 0 as internally that will disable all tap/click events. Set threshold to anything higher than 0, or omit it completely (defaults to 75) to make the tap functions works

$(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'
    });
});
Drakes
  • 23,254
  • 3
  • 51
  • 94