简体   繁体   English

在libgdx中使用AssetManager类

[英]Using the AssetManager class in libgdx

I am developing a platform game using libgdx. 我正在使用libgdx开发平台游戏。 I just started to use the AssetManager class. 我刚刚开始使用AssetManager类。 My game has one class for BaseLevel which all the other levels extend from it. 我的游戏为BaseLevel提供了一个类,所有其他级别都从该类扩展了。 And one class that load all the things for BaseLevel, after the user done with level one he will get to the next level and so on. 还有一个为BaseLevel加载所有东西的类,在用户完成第一级操作后,他将进入下一级,依此类推。 The player, the coins, and the enemies are using the same textures during all the levels in my game. 在游戏的所有关卡中,玩家,硬币和敌人都使用相同的纹理。

So my question is: Do I need to use my load screen in every start of the level and remove all the things when each level in hiding? 所以我的问题是:我需要在关卡的每个开始处使用加载屏幕,并在每个关卡隐藏时删除所有内容吗? Or I just need to use all the textures that have been loaded and not remove them at all? 还是只需要使用所有已加载的纹理,而根本不删除它们?

This is how I load all my Atlases and Textures: 这就是我加载所有地图集和纹理的方式:

     //Atlases
     game.manager.load("ui/buttonright.pack", TextureAtlas.class);
     game.manager.load("ui/buttonleft2.pack", TextureAtlas.class);
     game.manager.load("ui/jumpbutton.pack", TextureAtlas.class);
     game.manager.load("ui/nextlevel.pack", TextureAtlas.class);
     game.manager.load("ui/menupack.pack", TextureAtlas.class);
     game.manager.load("ui/pausebutton.pack", TextureAtlas.class);
     game.manager.load("ui/resumepack.pack", TextureAtlas.class);
     game.manager.load("ui/restartpack.pack", TextureAtlas.class);


     //Textures
     game.manager.load("img/background2.png", Texture.class);
     game.manager.load("img/background2up.png", Texture.class);

I use these all the textures and atlasses in all the levels, Am I need to remove them from the AssetMenager class when the level completed? 我在所有关卡中都使用了所有这些纹理和地图集,在关卡完成时是否需要将它们从AssetMenager类中删除?

No. If the assets are shared by the levels you don't need to unload them. 否。如果资产是按级别共享的,则无需卸载它们。 If want to unload them you should first load all the assets for the new level and then unload the assets for the old level. 如果要卸载它们,则应首先加载新级别的所有资产,然后卸载旧级别的资产。 AssetManager does reference counting so any asset that was used by both level would stay loaded (only if you load new then unload old, in that order). AssetManager会进行引用计数,因此两个级别使用的任何资产都将保持加载状态(仅当您按此顺序加载新资产然后卸载旧资产时)。

I see you have something called resumepack.pack and restartpack.pack . 我看到您有一个名为resumepack.packrestartpack.pack东西。 If either one of these is used to create a reloading type screen when your application comes back from a pause you might want to avoid using AssetManager for them. 如果您的应用程序从暂停中返回时,如果使用这些方法之一来创建重新加载类型的屏幕,则可能要避免为其使用AssetManager。 If you resume/reloading screen only uses traditional managed resources then you can use those resources to show a progress bar or similar as you resume (assuming you used Texture.setAssetManager(manager); ). 如果您的恢复/重新加载屏幕仅使用传统的托管资源,则可以在恢复时使用这些资源显示进度条或类似内容(假设您使用Texture.setAssetManager(manager); )。

to unload all the textures and atlas just use 卸载所有纹理和图集,只需使用

 game.manager.unload("ui/buttonright.pack");
 game.manager.unload("img/background2up.png");

and so on 等等

for more info on AssetManager use this link AssetManager 有关AssetManager的更多信息,请使用此链接AssetManager

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

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