Skip to main content
angelom77716812
Participant
May 2, 2017
Answered

Problem with GESTURE_SWIPE on EventListener

  • May 2, 2017
  • 1 reply
  • 345 views

I have two different elements that need a swipe gesture on the same scene.

I'e been working with

Multitouch.inputMode = MultitouchInputMode.GESTURE;

square1.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);

function onSwipe(e: TransformGestureEvent): void {

  if (e.offsetX == 1) {

  //User swiped towards right

  square1.x += 100;

  }

  if (e.offsetX == -1) {

  //User swiped towards left

  square1.x -= 100;

  }

  if (e.offsetY == 1) {

  //User swiped towards bottom

  square1.y += 100;

  }

  if (e.offsetY == -1) {

  //User swiped towards top

  square1.y -= 100;

  }

}

square2.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe2);

function onSwipe2(e: TransformGestureEvent): void {

  if (e.offsetX == 1) {

  //User swiped towards right

  square2.x += 100;

  }

  if (e.offsetX == -1) {

  //User swiped towards left

  square2.x -= 100;

  }

  if (e.offsetY == 1) {

  //User swiped towards bottom

  square2.y += 100;

  }

  if (e.offsetY == -1) {

  //User swiped towards top

  square2.y -= 100;

  }

}

square1 and square2 being my 2 elements.

I can swipe one and then the other one won't work. What could i do so the gesture doesn't get stuck on just one of the events?

This topic has been closed for replies.
Correct answer kglad

try testing on a mobile device instead of the emulator.

1 reply

kglad
Community Expert
Community Expert
May 2, 2017

there's no problem with your code.  there could be a problem with those two objects and their positions relative to each other.

angelom77716812
Participant
May 2, 2017

these are my two elements, they arent close to each other, i can swipe wherever i want on the screen and it would only affect the first one i interacted with

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 2, 2017

try testing on a mobile device instead of the emulator.