我尝试使用 SurfaceGestureDetector 这个类只使用 SurfaceGestureDetector 并且不起作用。ia msg "03-14 20:40:47.746: I/AndEngine(8963): org.anddev.andengine.input.touch.TouchEvent$TouchEventPool 已用尽,还有 0 个项目尚未回收。分配了 1 个。” 仅标记 Log.d("test", "TouchEvent"); 工作
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
// ===========================================================
}