从场景中分离我的精灵时,我得到一个超出范围的索引。请注意,我想从 Explosion 类中删除精灵,以使我的游戏类尽可能“干净”。
这是我创建精灵的地方。
mScene.registerUpdateHandler(new IUpdateHandler() {
public void onUpdate(float pSecondsElapsed) {
if(something) {
final Explosion expl = new Explosion(m.getX(), m.getY(),
getVertexBufferObjectManager(), false, 65);
mScene.attachChild(expl);
}
}
});
动画完成时移除精灵的爆炸类
public class Explosion extends AnimatedSprite {
private final Explosion self;
public Explosion(float pX, float pY, VertexBufferObjectManager pVertexBufferObjectManager,
boolean loopAnimation, long frameDurationEach) {
super(pX, pY, regExplosion, pVertexBufferObjectManager);
this.self = this;
this.animate(frameDurationEach, loopAnimation, new IAnimationListener() {
@Override
public void onAnimationStarted(AnimatedSprite pAnimatedSprite,
int pInitialLoopCount) {
}
@Override
public void onAnimationLoopFinished(AnimatedSprite pAnimatedSprite,
int pRemainingLoopCount, int pInitialLoopCount) {
}
@Override
public void onAnimationFrameChanged(AnimatedSprite pAnimatedSprite,
int pOldFrameIndex, int pNewFrameIndex) {
}
@Override
public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {
self.clearUpdateHandlers();
self.detachSelf();
self.dispose();
}
});
}