Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with GESTURE_SWIPE on EventListener

New Here ,
May 02, 2017 May 02, 2017

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?

275
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 02, 2017 May 02, 2017

try testing on a mobile device instead of the emulator.

Translate
Community Expert ,
May 02, 2017 May 02, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 02, 2017 May 02, 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

imagenflash.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2017 May 02, 2017

try testing on a mobile device instead of the emulator.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 02, 2017 May 02, 2017

You are right! Thank you very much, i was desperate!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2017 May 02, 2017
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines