彻底清除AndEngine现场 [英] Completely remove scene in AndEngine
问题描述
要我重新创建我的GameScene,但但当我切换水平约3〜4倍,我得到一个错误号12内存不足的错误在我的游戏水平之间切换。我需要能够以某种方式删除整个现场,并在后台运行停止。有没有办法做到这一点,所以我不内存跑出来了?
To switch between levels in my game I recreate my GameScene, but but when I switch levels about 3 or 4 times I get an errno 12 out of memory error. I need to be able to somehow delete the whole scene and stop it from running in the background. Is there a way to do this so I don't run out of memory?
编辑:
这是我的方法中,我加载新的场景。
This is my method in which I load the new scene.
public void loadGameScene(final Engine mEngine, final SharedPreferences sp, final String map) {
setScene(loadingScene);
ResourcesManager.getInstance().unloadMenuTextures();
mEngine.registerUpdateHandler(new TimerHandler(0.3f,
new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
ResourcesManager.getInstance().unloadGameTextures();
mEngine.unregisterUpdateHandler(pTimerHandler);
ResourcesManager.getInstance().loadGameResources();
GameScene gameScene = new GameScene();
gameScene.setSp(sp);
gameScene.loadLevel(map);
gameScene.loadMap(map);
setScene(gameScene);
}
}));
}
我把行
ResourcesManager.getInstance().unloadGameTextures()
但问题仍然存在。
but the problem persists.
推荐答案
如果您正确调用卸载()
上,当你打电话,你所使用的地图册 ResourcesManager.getInstance()。unloadGameTextures()
,你不应该得到一个内存不足的错误。
If you are correctly calling unload()
on the atlas that you are using when you call ResourcesManager.getInstance().unloadGameTextures()
, you shouldn't get an out of memory error.
我不知道你的ResourceManager的行为,但你并不需要所有recreat寰每次你改变一个场景(和重建我的意思是叫新BitmapAtlas()
或某些变体)。
I don't know how your ResourceManager behaves, but you don't need to recreat all the atlas everytime you change a scene (and by recreating I mean calling new BitmapAtlas()
or some variant).
您的ResourceManager应该建立在游戏的一开始就所有需要的对象(包括阿特拉斯)。然后,当你需要的地区一定的场景,你叫 atlas.load()
在具有这些地区和 atlas.unload()寰
其他地图集你不需要。
Your ResourceManager should create all the needed objects at the beggining of the game (this includes the atlas). Then when you need regions for a certain scene, you call atlas.load()
on the atlas that have those regions and atlas.unload()
on other atlas that you don't need.
这篇关于彻底清除AndEngine现场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!