Android libgdx使用手势监听器轻扫左右检测

Rag*_*dan 5 android libgdx android-gesture

我用libgdx在屏幕中央显示了一个图像.如果我向左滑动,图像应向左移动,如果我向右滑动图像应向右移动.

向左的后续滑动应该向左移动图像.同样的事情应该发生在右边.我用过GestureListener.

它在某种程度上起作用,如果我向左滑动第一个图像向左移动.但在那之后如果我试图向右滑动图像仍然向左移动.

那么我如何在libgdx中克服这个?

    class MyGestureListener implements GestureListener {

        @Override
        public boolean fling(float arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub


              if(arg0>0)
               iX += 20;
              else
             // else if(arg0*100>iX)
                  iX-=20;
               System.out.println("Hello..............."+iX);
            return true;
        }

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

   batch.draw(splashTexture, iX, iY);
Run Code Online (Sandbox Code Playgroud)

Rag*_*dan 4

我使用了此链接中的示例。https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/GestureDetectorTest.java

   @Override
   public boolean fling(float velocityX, float velocityY, int button) {
       if(Math.abs(velocityX)>Math.abs(velocityY)){
               if(velocityX>0){
                       iX+=20;//x cordinate
               }else if (velocityX<0){
                      iX-=20;
               } else {
                 // Do nothing.
               }
       }else{

          // Ignore the input, because we don't care about up/down swipes.
       }
 return true; 
}
Run Code Online (Sandbox Code Playgroud)