2

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)

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

Fish
  • 1,689
  • 1
  • 18
  • 28
  • 1
    Where do you call `manager.update()`? If you don't call it, the `manager` won't continue to load the `Assets`. The other 3 files might be verry small and loaded "immediatly", while the 4th is bigger or simply all 4 together are to big to be loaded "immediatly" so one isn't loaded. – Robert P Apr 22 '15 at 15:55
  • also think about updating or answering your other question. This solution should also solve the problem of your other question. – Robert P Apr 23 '15 at 06:05
  • @Springrbua I have changed the assetManager section a lot after the confusing comments I have recieved, so this question is quite unrelated to the other, Thanks for reminding – Fish Apr 23 '15 at 10:14
  • there was only one comment to the question and that comment was simmilar to the accepted solution here. Also the problem here and in the other question are basicly the same, you never called `AssetManager#update` or `AssetManager#finishLoading`. So i guess the questions are related and you might consider updating or answering it. It might help other peoples in future. Thanks – Robert P Apr 23 '15 at 14:25

1 Answers1

2

Solution:

Add

manager.finishLoading();

at the end of load method.


If you want to do it asynchronously, you should use manager.update() in render loop.

Refer to this for more information.


Try to avoid public fields and static methods. (Not related to the question).

Tanmay Patil
  • 6,882
  • 2
  • 25
  • 45
  • Why avoid static methods, want to do static because I no longer need to create an instance every screen – Fish Apr 22 '15 at 19:43
  • You can share the instance between all screens. Having one instance for the Game object will allow you to reason about when to call dispose method. – Tanmay Patil Apr 23 '15 at 01:27
  • @TanmayPatil please take a look at my question http://stackoverflow.com/questions/36586597/libgdx-non-static-assetmanager-not-working – Green_qaue Apr 13 '16 at 01:22