我有一个AnimatedSprite元素,我想对它应用一些修饰符(AlphaModifier,ScaleModifier,...)
修改器完成后,应删除AnimatedSprite元素。 正常调用时removeFace()方法正常工作。但是我在onModifierFinished()方法中调用它,然后我收到错误。我是这样实现的。
void removeBallWithModifier(final AnimatedSprite ball) {
final LoopEntityModifier em = new LoopEntityModifier(
new SequenceEntityModifier(new ParallelEntityModifier(
new AlphaModifier(1, 1, 0.4f), new ScaleModifier(1, 1,
0.4f), new RotationByModifier(1, 270))), 1,
new IEntityModifierListener() {
@Override
public void onModifierStarted(IModifier<IEntity> pModifier,
IEntity pItem) {
}
@Override
public void onModifierFinished(
IModifier<IEntity> pModifier, IEntity pItem) {
ball.setVisible(false);
removeFace(ball);
}
});
ball.registerEntityModifier(em);
}
void removeFace(final AnimatedSprite face) {
final PhysicsConnector facePhysicsConnector = this.mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(face);
this.mPhysicsWorld.unregisterPhysicsConnector(facePhysicsConnector);
this.mPhysicsWorld.destroyBody(facePhysicsConnector.getBody());
this.mScene.unregisterTouchArea(face);
this.mScene.detachChild(face);
System.gc();
}
堆栈跟踪:
02-20 00:56:39.008: W/dalvikvm(14094): threadid=8: thread exiting with uncaught exception (group=0x4001d7d0)
02-20 00:56:39.023: E/AndroidRuntime(14094): FATAL EXCEPTION: UpdateThread
02-20 00:56:39.023: E/AndroidRuntime(14094): java.lang.IndexOutOfBoundsException: Invalid index 9, size is 9
02-20 00:56:39.023: E/AndroidRuntime(14094): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
02-20 00:56:39.023: E/AndroidRuntime(14094): at java.util.ArrayList.get(ArrayList.java:311)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1402)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.engine.Engine.onUpdateScene(Engine.java:591)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.engine.Engine.onUpdate(Engine.java:586)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
02-20 00:56:39.023: E/AndroidRuntime(14094): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)
答案 0 :(得分:0)
也许你应该尝试这样的事情
YourClassName.this.runOnUiThread(new Runnable() {
@Override
public void run() {
ball.setVisible(false);
removeFace(ball);
}
});