LIBGDX:什么时候应该丢弃TextureAtlas?

时间:2014-05-29 04:40:18

标签: java resources libgdx

在LIBGDX文档"必须处理TextureAtlas以释放支持纹理所消耗的资源。" LIBGDX维基中的最后一行说" TextureAtlas保留所有页面纹理。处理TextureAtlas将处理所有页面纹理。" 所以我什么时候应该处理一个本地的TextureAtlas,其纹理被其他类使用?

public class loader(String region) {
  public TextureRegion TextureLoader() {
    TextureAtlas atlas = new TextureAtlas("zzz.pack");
    TextureRegion textureRegion = atlas.findRegion(region);
    //atlas.dispose();//if I uncomment this line, no texture will be drawn, just a blank black area instead of the loaded textureRegion
    return ;
    }
  }

public class player() {
  public player() {
    TextureRegion textureRegion = loader(region);
    //draw textureRegion
    }
  }

1 个答案:

答案 0 :(得分:2)

如果不再需要,请将其丢弃。但这取决于你在这个地图册中有哪些纹理。

可能是您退出游戏并返回主菜单。在这种情况下,可以处理具有所有与游戏相关的纹理的纹理图集。

如果您的游戏每个级别都有一个纹理图集,因为级别看起来不同,那么您可以在切换关卡时处理它们。

然而,在大多数情况下,当玩家完全退出游戏时,你可能只会丢弃地图集。您应该使用AssetManager加载地图集,并且在游戏退出时处置资产管理器始终是个好主意。这将处置仍然加载的所有资产,并将清理所有内容。

相关问题