I am using "AndEngine" and I would like to know if I am following the best practice when I want to refresh the entity.
Let say, I have 2 sprites and I want change them into 2 another sprites.
I usually do it like this :
class MainClass {
private Sprite sprite1;
private Sprite sprite2;
private void someMethod(){
sprite1 = new Sprite(0,0,someRegion1,getVertexBufferObjectManager());
sprite2 = new Sprite(10,10,someRegion2,getVertexBufferObjectManager());
attachChild(sprite1);
attachChild(sprite2);
}
private void refreshSprites(Sprite pSprite1, Sprite pSprite2){
Sprite temp1 = sprite1;
Sprite temp2 = sprite2;
sprite1 = sprite2 = null;
runOnUpdateThread(new Runnable() {
@Override
public void run() {
temp1.detachSelf();
temp2.detachSelf();
}
});
sprite1 = pSprite1;
sprite2 = pSprite2;
attachChild(sprite1);
attachChild(sprite2);
}
}