简体   繁体   English

LIbgdx - 为什么 AssetManager 不工作?

[英]LIbgdx - Why is AssetManager not working?

I have tried to use Asset Manager to load some assets.我尝试使用资产管理器加载一些资产。 Everything works fine, except for one part.一切正常,除了一部分。 Here is my code这是我的代码

My AssetHandler Class (contains assetManager)我的 AssetHandler 类(包含 assetManager)

public class AssetHandler {
    public static AssetManager manager;

    public static String wallFile = "3d/wall.g3db";
    public static String floorFile = "3d/floor.g3db";
    public static String stairsFile = "3d/stairs.g3db";
    public static String characterFile = "3d/character.g3db";

    public static void load() {
        manager = new AssetManager();

        manager.load(wallFile, Model.class);
        manager.load(floorFile, Model.class);
        manager.load(stairsFile, Model.class);
        manager.load(characterFile, Model.class);

    }

    public static void dispose() {
        manager.clear();
        manager.dispose();
    }

    public static void dispose(String fileName) {
        manager.unload(fileName);
    }

}

when I attempt to use the file, I wrote:当我尝试使用该文件时,我写道:

 model = AssetHandler.manager.get(AssetHandler.characterFile, Model.class);
 model = AssetHandler.manager.get(AssetHandler.wallFile, Model.class);

everything works but character file doesn't Other files do, but just this one file don't一切正常,但字符文件无效 其他文件有效,但仅此一个文件无效

Please Help I don't get why No errors/ exceptions poped up请帮助我不明白为什么没有弹出错误/异常

Solution:解决方案:

Add添加

manager.finishLoading();

at the end of load method.load方法结束时。


If you want to do it asynchronously, you should use manager.update() in render loop.如果你想异步进行,你应该在渲染循环中使用manager.update()

Refer to this for more information.有关更多信息,请参阅内容。


Try to avoid public fields and static methods.尽量避免公共字段和静态方法。 (Not related to the question). (与问题无关)。

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

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