0

I try to use SurfaceGestureDetector This class use only SurfaceGestureDetector and not work. i a msg "03-14 20:40:47.746: I/AndEngine(8963): org.anddev.andengine.input.touch.TouchEvent$TouchEventPool was exhausted, with 0 item not yet recycled. Allocated 1 more." Only Tag Log.d("test", "TouchEvent"); work

public class MainActivity extends BaseGameActivity {
// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 320;

// ===========================================================
// Fields
// ===========================================================

private Camera mCamera;
//private Texture mTexture, mBatTexture;
//private TiledTextureRegion mBatTextureRegion;
//private TextureRegion mSplashTextureRegion;
private Handler mHandler;
//static protected Music mMusic;


private Scene mScene;

private SurfaceGestureDetector surfaceGestureDetector;

private TouchEvent pSceneTouchEvent;

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
public Engine onLoadEngine() {
    mHandler = new Handler();
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}

@Override
public void onLoadResources() {

    }

@Override
public Scene onLoadScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    this.mScene = new Scene();

    setupGestureDetaction();

    return mScene;
}

@Override
public void onLoadComplete() {
    //mHandler.post(mLaunchTask);
}

private Runnable mLaunchTask = new Runnable() {
    public void run() {
        Intent myIntent = new Intent(MainActivity.this, TMXTiledMapExample.class);
        MainActivity.this.startActivity(myIntent);
    }
 };


private void setupGestureDetaction(){



      surfaceGestureDetector = new SurfaceGestureDetector(1f) {         

        @Override
        protected boolean onSingleTap() {
            // TODO Auto-generated method stub
            Log.d("test", "onSingleTap"); 
            return true;
        }

        @Override
        protected boolean onDoubleTap() {
            Log.d("test", "onDoubleTap");
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        protected boolean onSwipeUp() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        protected boolean onSwipeDown() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        protected boolean onSwipeLeft() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        protected boolean onSwipeRight() {
            // TODO Auto-generated method stub
            return false;
        }



   @Override
       public boolean onManagedTouchEvent(TouchEvent pSceneTouchEvent) { 
        return super.onManagedTouchEvent(pSceneTouchEvent);
       }

       @Override
       public boolean onSceneTouchEvent(Scene pScene,
         TouchEvent pSceneTouchEvent) {     
           Log.d("test", "TouchEvent");

        return super.onSceneTouchEvent(pScene, pSceneTouchEvent);
       //return false;

       }
      };

 //      if (pSceneTouchEvent!=null){
     // TouchEvent.recycle(pSceneTouchEvent);}


      surfaceGestureDetector.setEnabled(true);

      mScene.setOnSceneTouchListener(surfaceGestureDetector);
    }



// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
user2080866
  • 459
  • 2
  • 6
  • 18
  • i try this and work: http://www.androidsnippets.com/gesturedetector-and-gesturedetectorongesturelistener but i need onDoubleTap() it would seem that return super.onSceneTouchEvent(pScene, pSceneTouchEvent); is incorrect i search for good code since yesterday ... – user2080866 Mar 15 '13 at 14:11
  • i fixed for double tap here http://stackoverflow.com/questions/2640119/how-to-detect-doubletap-on-a-view but but I still can not run surfaceGestureDetector – user2080866 Mar 15 '13 at 14:23

1 Answers1

0

This question is old as i write this reply, but the log message you show above is a not an error message. It is an appropriate message letting you know that the Object Pool for touch events did not contain any touches, so it created more.

This is a normal message from Andengine, and you will see it when you first start using touches, but less as the app runs, because the pool size will grow, and so a touch will be recycled rather than created.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47