在游戏场景中,当玩家开火时,敌人会自动动画并离开场景。我尝试了很多,但没有找到解决方案。
这是我的代码。
it = bulletList.iterator();
while (it.hasNext()) {
final Bullet b = (Bullet) it.next();
if (b.sprite.collidesWith(enemy)) {
engine.runOnUpdateThread(new Runnable() {
public void run() {
enemy.animate(new long[]{100,100,100,100,100},10,14,1
, new IAnimationListener() {
@Override
public void onAnimationStarted(AnimatedSprite pAnimatedSprite,int
pInitialLoopCount) {
}
@Override
public void onAnimationLoopFinished(AnimatedSprite pAnimatedSprite,
int pRemainingLoopCount, int
pInitialLoopCount) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationFrameChanged(AnimatedSprite pAnimatedSprite,
int pOldFrameIndex, int pNewFrameIndex) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {
// TODO Auto-generated method stub
detachChild(sprite);
}
});
enemy.setIgnoreUpdate(true);
it.remove();
break;
}
}
}