6 Replies Latest reply on Jul 10, 2013 10:57 AM by sinious

    How to get the coordinates of a Swipe Gesture?

    Daniel12378992 Level 1

      Hi guys!I'm building a game similar to Fruit Ninja and i recently encountered the following problem:how do i access the touch points of a swipe event cause as you now in order to tear a fruit apart i need to know if the swipe points are the same as a fruit's location.

      So basically it's something like:

      If (Swipe.x==fruit.x){

      Destroyfruit();

      }

      So is there any way to figure out the coordinates of a Swipe?

      Thanks

        • 1. Re: How to get the coordinates of a Swipe Gesture?
          kglad Adobe Community Professional & MVP

          touchevents have localX,localY,stageX,stageY properties you can use.

          1 person found this helpful
          • 2. Re: How to get the coordinates of a Swipe Gesture?
            sinious Most Valuable Participant

            Gestures have phases. Swipe has a begin and end and fires off no events outside those. You'll only be able to get the coordinates of the begin of the swipe and at the end. Don't use gestures, use regular Touch events with stageX and stageY (or localX and localY if constrained to a certain area). Those events fire rapidly and continuously. You can simplify it by just listening to TouchEvent.TOUCH_MOVE since it fires so rapidly.

            • 3. Re: How to get the coordinates of a Swipe Gesture?
              Daniel12378992 Level 1

              So basicly i can get the desired result by using regular Touch events and TouchPhase.MOVED,right?

              • 4. Re: How to get the coordinates of a Swipe Gesture?
                sinious Most Valuable Participant

                TouchEvent.TOUCH_MOVE, I'm so starling minded these days . A quick example of a class that'll draw a rect the size of the screen. Run it in debug mode on your device and see the properties returned:

                 

                package

                {

                          import flash.display.Sprite;

                          import flash.display.StageAlign;

                          import flash.display.StageScaleMode;

                          import flash.events.Event;

                          import flash.events.TouchEvent;

                          import flash.ui.Multitouch;

                          import flash.ui.MultitouchInputMode;

                 

                          public class TouchTesting extends Sprite

                          {

                                    public function TouchTesting()

                                    {

                                              super();

                 

                                              // support autoOrients

                                              stage.align = StageAlign.TOP_LEFT;

                                              stage.scaleMode = StageScaleMode.NO_SCALE;

                 

                                              Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

                 

                                              addEventListener(Event.ACTIVATE, onA);

                                    }

                 

                                    protected function onA(event:Event):void

                                    {

                                              removeEventListener(Event.ACTIVATE, onA);

                                              var a:Sprite = new Sprite();

                                              addChild(a);

                                              a.graphics.beginFill(0xFF0000,1);

                                              a.graphics.drawRect(0,0,stage.fullScreenWidth,stage.fullScreenHeight);

                                              a.graphics.endFill();

                                              a.addEventListener(TouchEvent.TOUCH_MOVE, onMove);

                                    }

                 

                                    protected function onMove(e:TouchEvent):void

                                    {

                                              trace(e);

                                    }

                          }

                }

                • 5. Re: How to get the coordinates of a Swipe Gesture?
                  Daniel12378992 Level 1

                  Thanks)))I get that now

                  • 6. Re: How to get the coordinates of a Swipe Gesture?
                    sinious Most Valuable Participant

                    You're welcome and good luck!