我使用onSceneTouchEvent对TMX地图移动播放器:GLES2 TouchEventPool耗尽
@Override
public Scene onCreateScene() {
...
mScene.setOnSceneTouchListener(this);
}
...
@Override
public boolean onSceneTouchEvent(Scene pScene, final TouchEvent pSceneTouchEvent) {
switch(pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
mLastMotionX = pSceneTouchEvent.getX();
mLastMotionY = pSceneTouchEvent.getY();
break;
case TouchEvent.ACTION_MOVE:
mLastMotionX1 = pSceneTouchEvent.getX();
mLastMotionY1 = pSceneTouchEvent.getY();
SpeedVector(mLastMotionX, mLastMotionY, mLastMotionX1,
mLastMotionY1);
break;
case TouchEvent.ACTION_UP:
mLastMotionX2 = pSceneTouchEvent.getX();
mLastMotionY2 = pSceneTouchEvent.getY();
SpeedVectorStop(mLastMotionX, mLastMotionY, mLastMotionX2,
mLastMotionY2);
break;
}
return false;
}
...
public void SpeedVector(float x1, float y1, float x2, float y2) {
if ((Math.abs(x2 - x1) < 55) && (Math.abs(y2 - y1) < 55)) {
float r = (float) Math.sqrt(((x2 - x1) * (x2 - x1))
+ ((y2 - y1) * (y2 - y1)));
float rx = (x2 - x1)/r;
float ry = (y2 - y1)/r;
new Vector2(rx * 100, ry * 100);
new Vector2(x2, y2);
if (speedThread) {
mPlayerBody.setLinearVelocity(rx * 15, ry * 15);
} else
mPlayerBody.setLinearVelocity(rx * 5, ry * 5);
}
}
public void SpeedVectorStop(float x1, float y1, float x2, float y2) {
if ((Math.abs(x2 - x1) < 10) && (Math.abs(y2 - y1) < 10)) {
mPlayerBody.setLinearVelocity(0, 0);
}
}
而且现场有很多是追求玩家(简单的AI)其他小精灵(敌人)的。他们的位置和速度根据与玩家的距离而变化。 因此,所有数据将在下一方法更新:
@Override
public final void onUpdate(final float pSecondsElapsed) {
//some code
}
当我触碰现场几次 - AndEngine将在这里崩溃 是一个logcat的:
05-05 17: 13:06.539:V/AndEngine(2676): org.andengine.input.touch.TouchEvent $ TouchEventPool was exhausted,2 item尚未回收。分配了1个。 05-05 17:13:06.539:V/AndEngine(2676): org.andengine.util.adt.pool.PoolUpdateHandler $ 1 已用尽,2个项目尚未回收。分配了1个。 05-05 17:13:06.559:V/AndEngine(2676): org.andengine.input.touch.TouchEvent $ TouchEventPool was exhausted,3 item还未回收。分配了1个。 05-05 17:13:06.559:V/AndEngine(2676): org.andengine.util.adt.pool.PoolUpdateHandler $ 1 已用尽,3件商品尚未回收。分配了1个。 05-05 17:13:06.579:V/AndEngine(2676): org.andengine.input.touch.TouchEvent $ TouchEventPool was exhausted,4 item还未回收。分配了1个。 05-05 17:13:06.579:V/AndEngine(2676): org.andengine.util.adt.pool.PoolUpdateHandler $ 1 已用尽,4件商品尚未回收。分配了1个。
等
任何人都遇到过这个问题?
的问题是非常紧迫和无解,但(被包含作为TouchEvent类中的私有静态成员TouchEventPool产生
但我怎么能从类TouchEventPool调用抽象构造函数? – user2352679 2013-05-07 13:12:53
也许: private static int pInitialSize; \t private static final TouchEventPool TOUCHEVENT_POOL = new TouchEventPool(pInitialSize); ... ... ... \t公共静态最后一类TouchEventPool扩展GenericPool { \t \t // ==================== ======================================= \t \t //用于/从SuperClass /接口 \t \t // ============================================ =============== \t \t public TouchEventPool(final int pInitialSize) \t \t { \t \t \t super(pInitialSize); \t \t} \t \t @覆盖 \t \t保护的TouchEvent onAllocatePoolItem(){ \t \t \t回新的TouchEvent(); \t \t} \t} –
user2352679
2013-05-07 13:24:53
您可以修改AndEngine TouchEvent文件,向TouchEventPool添加一个构造函数并从它调用super(所需的事件数)。但我必须补充说这不是你的崩溃的原因。这是AndEngine的标准信息。所以不要停止寻找错误;) – 2013-05-07 17:00:23