How can repair this error? “java.lang.IndexOutOfBoundsException”

后端 未结 3 1018
眼角桃花
眼角桃花 2021-01-17 02:03

I\'m trying to do a game with andengine library.

When the Sprite Enemy1Sprite reach the top of the camera, and I detach it, this exception

3条回答
  •  被撕碎了的回忆
    2021-01-17 02:39

    You've answered your own question really - Marcelo is correct, the issue is not in the code you posted, it's where you are doing the detachChild call - you need to call that on the Update Thread, as in

    runOnUpdateThread(new Runnable() {
    @Override
    public void run() {
    // TODO Auto-generated method stub
        yourScene.detachChild(yourEnemySprite);
    }
    });
    

提交回复
热议问题