简体   繁体   English

如何在发动机中正确销毁和重建场景?

[英]How to destroy and recreate a scene in andengine correctly?

In andAngine I need to destroy a Scene in andangine and to recreate it in order to restart the game variables and listeners and gamelogic. 在andAngine中我需要在andangine中销毁一个场景并重新创建它以重新启动游戏变量和监听器以及gamelogic。 i use 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 to go wrong when I recreate the third time the scene. 当我重新创建第三次场景时,似乎出现了问题。 Sprites doesn't display..are distorted or something doesn't display at all. 精灵不显示..扭曲或根本不显示。 Can anyone explain to me if I correctly initialize and destroy the scene ? 如果我正确初始化并破坏场景,有人可以向我解释吗?

Personally, I would create the scene once the first time it is used. 就个人而言,我会在第一次使用时创建场景。

To change the scene, do your removal stuff as you've shown, I wouldn't bother with the call to System.gc(), and then instead of creating a new Scene() - just call scene.reset(), scene.dosomestuff, etc 要更改场景,请按照您的显示进行删除操作,我不打扰调用System.gc(),然后再创建一个新的Scene() - 只需调用scene.reset(),场景.dosomestuff等

Creating a new Scene like you show looks like a major memory leak, or at least a possible leak. 像你一样创建一个新的场景看起来像一个主要的内存泄漏,或者至少是一个可能的泄漏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM