0

I am wondering how to use a gesture listener and I want to detect in which direction the swipe is going on and I want to move the texture. My game is almost done and is ready to be on the android Play Store but I need to use swipe as an input.
I have looked at many articles and many questions on stack overflow which are very similar, but I am a sixth grader and for me some of the explanations in stack overflow I have seen, or simply not understandable for me. May somebody please explain every single part of gesture Listener, how to set it up, how to detect the direction of the swipes.

I do have it implemented though but some parts are simply not working.. public class PlayScreen extends InputListener implements Screen, InputProcessor, GestureListener{ as you can see I have implemented the gesture listener

@Override
public boolean touchDown(float x, float y, int pointer, int button) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean tap(float x, float y, int count, int button) {
    // TODO Auto-generated method stub
    System.out.println("got tapped!");
    return true;
}

@Override
public boolean longPress(float x, float y) {
    // TODO Auto-generated method stub
    return false;
}



@Override
    public boolean fling(float velocityX, float velocityY, int button) {
        // TODO Auto-generated method stub
        System.out.println(velocityX + ": " + velocityY);
         if(Math.abs(velocityX)>Math.abs(velocityY)){
             if(velocityX>0){
                     position5.x+=100;//x cordinate
             }else if (velocityX<0){
                    position5.x-=100;
             } else {
               // Do nothing.
             }
     }else{


     }
return true; 
    }

@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean panStop(float x, float y, int pointer, int button) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean zoom(float initialDistance, float distance) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
        Vector2 pointer1, Vector2 pointer2) {
    // TODO Auto-generated method stub
    return false;
}

I also put the following in my show method(I have implemented screen)

Gdx.input.setInputProcessor(new GestureDetector(0.0f, 0.0f,0.0f, 5f,new PlayScreen(game)));

Can somebody please explain what I am missing and give me a nice overview of the gesture listener?

Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
ilikeyoyo
  • 168
  • 4
  • 20
  • http://stackoverflow.com/questions/15177049/android-libgdx-swipe-left-and-right-detection-using-gesture-listener – Raghunandan Jun 19 '14 at 03:29
  • Well I copied your code as you can see with the fling method, that was from that question yet it is STILL not working? do you know why? – ilikeyoyo Jun 19 '14 at 04:22
  • i have not worked on ligbdx for a long time. So i can't comment further – Raghunandan Jun 19 '14 at 04:23
  • ok, no problem I'll put some more effort but tell me, did that snippet of code you gave in the link, the answer that you gave, does that work for you? That is all I want to know. – ilikeyoyo Jun 19 '14 at 04:31
  • Can you explain what you mean by "not working"? Is the `fling` callback being invoked when you expect, but it is just not creating the impact you want? Or is that callback not even being called when you expect it to? – P.T. Jun 19 '14 at 06:05
  • No It is not being invoked, The result is not coming out, the position does not change. And I tried printing out something on the tap function and that did not work either, so i am guessing it is not invoked. – ilikeyoyo Jun 19 '14 at 14:48

1 Answers1

0

Oh i got the answer i put a really stupid line of code i forgot to display, this line

Gdx.input.setInputProcessor(this);

Anyways, thank you raghunandan for your link above, very smart way to detect swipe direction

ilikeyoyo
  • 168
  • 4
  • 20