How to destroy and recreate a scene in andengine?

In andAngine, I need to destroy the scene in andangine and recreate it in order to restart game variables and listeners and gamelogic. I am using this code:

scene.detachChildren();
scene.clearEntityModifiers();
scene.clearTouchAreas();
scene.clearUpdateHandlers();

System.gc();
thisengine.setScene(menuscene);

and then I recreate the scene

scene = new Scene();
scene.dosomestuff
thisengine.setScene(scene);

Something seems wrong when I recreate the scene for the third time. Sprites are not displayed ... distorted or something is not displayed at all. Can someone explain to me if I correctly initialize and destroy the scene?

+5
source share
1 answer

Personally, I would create a scene on first use.

To change the scene, do the deletion, as you showed, I would not worry about calling System.gc (), and then instead of creating a new scene () - just call the scene .reset (), scene.dosomestuff, etc.

, , , , .

+4

All Articles