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?