1

What I am trying to do is use the android.view.GestureDetector and android.view.ScaleGestureDetector classes in Android but they appear to be disabled by LibGDX. I need to specifically get access to the MotionEvent objects which Android generates when a user touches the screen. Can anyone help point me in the right direction or confirm if indeed LibGDX is disabling them? Thanks in advance.

Scott Kingdon
  • 351
  • 1
  • 2
  • 9
  • http://stackoverflow.com/questions/15177049/android-libgdx-swipe-left-and-right-detection-using-gesture-listener. check this if it helps – Raghunandan Jan 08 '14 at 03:53
  • I checked out the link you provided and it didn't help as I need access to the Android MotionEvent objects which get generated when a user touches the screen. – Scott Kingdon Jan 08 '14 at 05:08

1 Answers1

3

There is already an abstraction of the GestureDetector on libgdx. the GestureListener You can use it like this:

public class MyGestureListener implements GestureListener {

   @Override
   public boolean touchDown (int x, int y, int pointer) {
      return false;
   }

   @Override
   public boolean tap (int x, int y, int count) {
      return false;
   }

   @Override
   public boolean longPress (int x, int y) {
      return false;
   }

   @Override
   public boolean fling (float velocityX, float velocityY) {
      return false;
   }

   @Override
   public boolean pan (int x, int y, int deltaX, int deltaY) {
      return false;
   }

   @Override
   public boolean zoom (float originalDistance, float currentDistance) {
      return false;
   }

   @Override
   public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
      return false;
   }
}

Don't forget to set it as an InputProcessor

Gdx.input.setInputProcessor(new GestureDetector(new MyGestureListener()));

Reference: Gesture Detection

As a little plus, if you find something Android specific that you would like to use with libgdx, this link may help you: Interfacing with Platform Specific Code

Daahrien
  • 10,190
  • 6
  • 39
  • 71
  • Sorry but once again I need to get access to the Android MotionEvent objects as they are being generated when a user touches the screen. – Scott Kingdon Jan 08 '14 at 05:34
  • 2
    You can't use the MotionEvent in Libgdx directly because that would mean, that you just develop for android. Those gestureListener does detect those Events even on desktop or inside of the Browser! If you want to get those directly see the libgdx wiki how to pass android stuff directly to the core Projekt. (Eg see the Tutorial for AdMob) https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx this is the correct answer if you want to say in libgdx "way". – bemeyer Jan 08 '14 at 09:39