0

我尝试使用 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
// ===========================================================
}
4

1 回答 1

0

这个问题在我写这个回复时很老,但是您在上面显示的日志消息不是错误消息。这是一条适当的消息,让您知道触摸事件的对象池不包含任何触摸,因此它创建了更多。

这是来自 Andengine 的正常消息,当您第一次开始使用触摸时您会看到它,但随着应用程序的运行而减少,因为池大小会增长,因此触摸将被回收而不是创建。

于 2013-08-05T18:35:27.167 回答