0

我有一个射击游戏,你向相反的方向射击两颗子弹,所以如果敌人靠近子弹的起点(敌人在子弹起点的区域内)就会发生错误,

这是我的代码:

if((_target.collidesWith(bullet))){

                    resourcesManager.enemyPool.recyclePoolItem(_target);
                    targets.remove();
                    score=score+1;

                }
                if((_target.collidesWith(bullet2))){
                    resourcesManager.enemyPool.recyclePoolItem(_target);
                    targets.remove();
                    score=score+1;
                    break;
                }

错误日志:

09-30 09:47:23.530: E/AndroidRuntime(1167): in writeCrashedAppName, pkgName :com.www.tangent
09-30 09:47:23.550: I/Process(1167): Sending signal. PID: 1167 SIG: 9
09-30 09:47:23.550: E/AndroidRuntime(1167): FATAL EXCEPTION: UpdateThread
09-30 09:47:23.550: E/AndroidRuntime(1167): java.lang.IllegalStateException
09-30 09:47:23.550: E/AndroidRuntime(1167):     at java.util.LinkedList$LinkIterator.remove(LinkedList.java:164)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at com.www.scene.WeaponSelectScene$1.onUpdate(WeaponSelectScene.java:318)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.handler.UpdateHandlerList.onUpdate(UpdateHandlerList.java:47)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1395)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:288)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.Engine.onUpdateScene(Engine.java:591)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.Engine.onUpdate(Engine.java:586)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.LimitedFPSEngine.onUpdate(LimitedFPSEngine.java:56)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
09-30 09:47:23.550: E/AndroidRuntime(1167):     at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)
09-30 09:47:23.570: I/BstWindowOrientationListener(521): getCurrentRotation(0)
09-30 09:47:23.570: I/ActivityManager(521): Process com.www.tangent (pid 1167) has died.
09-30 09:47:23.570: I/WindowManager(521): WIN DEATH: Window{b4846b48 SurfaceView paused=false}
09-30 09:47:23.590: E/InputDispatcher(521): channel 'b472fa40 com.www.tangent/com.www.tangent.GameActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
09-30 09:47:23.590: E/InputDispatcher(521): channel 'b472fa40 com.www.tangent/com.www.tangent.GameActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-30 09:47:23.590: I/WindowManager(521): WIN DEATH: Window{b472fa40 com.www.tangent/com.www.tangent.GameActivity paused=false}
4

1 回答 1

1

我只是遇到了同样的问题,而您没有答案的问题使我找到了我的问题。

实际上,在这里您可以同时删除您的 recyclePoolItem,因为在一帧中,您删除了两次相同的对象(当您的 _target 与两个对象碰撞时发生)。要纠正这个问题,只需在“if”语句下使用“else if”而不是“if”来编写代码:

if((_target.collidesWith(bullet))){
    resourcesManager.enemyPool.recyclePoolItem(_target);
    targets.remove();
    score=score+1;
} else if((_target.collidesWith(bullet2))){
    resourcesManager.enemyPool.recyclePoolItem(_target);
    targets.remove();
    score=score+1;
}
于 2014-01-31T23:00:49.980 回答