5

画面中央に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);
4

2 に答える 2

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; 
}
于 2013-03-06T17:36:59.223 に答える