I've tried to implement the AssetManager into my project. Now i can't figure out what i'm doing wrong with the AssetManager. I've googled, and tried different things. But it seems that no one else have ever experienced this kind of problem with the AssetManager. I used .finisLoading(), but afterwards if i ask .isLoaded it says that it hasn't been loaded.
The wiki tutorial here says this
manager.load("data/mytexture.png", Texture.class);
....
manager.finishLoading();
...
Texture tex = manager.get("data/mytexture.png", Texture.class);
I have this Code
// fullFile e.g. "D:\\folder\\subfolder\\subsubfolder\\jpg.jpg"
if (!new FileHandle(fullFile).exists()) {
System.err.printf("invalid file \"%s\"\n",fullFile);
System.exit(1);
}
if (!manager.isLoaded(fullFile,Texture.class)) manager.load(fullFile,Texture.class);
manager.finishLoading();
if (!manager.isLoaded(fullFile,Texture.class)) {
return = new Sprite(new Texture("D:\\folder\\subfolder\\subsubfolder\\placeholder.jpg"));
} else {
return new Sprite(manager.get(fullFile,Texture.class));
}
the manger is
AssetManager manager = new AssetManager(new FileHandleResolver() {
@Override
public FileHandle resolve(String fullFile ) {
FileHandle fh = new FileHandle(fullFile);
if (!fh.exists()) {
System.err.printf("invalid file \"%s\"\n",fh.path());
System.exit(1);
}
return fh;
}
What I've tried so far
Run the Project created by gdx-setup.jar -> Couldn't load file: badlogic.jpg
Code from: Juan Javier Cassani
public static void test() {
AbsoluteFileHandleResolver fileHandleResolver = new AbsoluteFileHandleResolver();
AssetManager manager = new AssetManager(fileHandleResolver);
//This could be anywhere else
String fileName = "D:\\blablabla\\my_project\\core\\assets\\badlogic.jpg";
if (!new FileHandle(fileName).exists()) {
Gdx.app.error("Blub", "invalid file '" + fileName + "'");
Gdx.app.exit();
}
if (!manager.isLoaded(fileName, Texture.class))
manager.load(fileName, Texture.class);
manager.finishLoading();
if (manager.isLoaded(fileName, Texture.class))
Gdx.app.log("Blub", "Texture loaded!");
else
Gdx.app.log("Blub", "Texture not loaded!");
}
-> Blub: Texture not loaded!
Versions:
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
ashley-1.3.1.jar
box2dlights-1.3.jar
gdx-1.4.1.jar
gdx-ai-1.4.0.jar
gdx-backend-lwjgl-1.4.1.jar
gdx-box2d-1.4.1.jar
gdx-box2d-platform-1.4.1-natives-desktop.jar
gdx-bullet-1.4.1.jar
gdx-bullet-platform-1.4.1-natives-desktop.jar
gdx-controllers-1.4.1.jar
gdx-controllers-desktop-1.4.1.jar
gdx-controllers-platform-1.4.1-natives-desktop.jar
gdx-freetype-1.4.1.jar
gdx-freetype-platform-1.4.1-natives-desktop.jar
gdx-platform-1.4.1-natives-desktop.jar
gdx-tools-1.4.1.jar
jinput-2.0.5.jar
jinput-platform-2.0.5-natives-linux.jar
jinput-platform-2.0.5-natives-osx.jar
jinput-platform-2.0.5-natives-windows.jar
jlayer-1.0.1-gdx.jar
jorbis-0.0.17.jar
jutils-1.0.0.jar
lwjgl-2.9.1.jar
lwjgl-platform-2.9.1-natives-linux.jar
lwjgl-platform-2.9.1-natives-osx.jar
lwjgl-platform-2.9.1-natives-windows.jar
lwjgl_util-2.9.1.jar
I just read (again) here that i had to set the working directory to your_project_path/core/assets/
. I somehow forgot that step after setup.
But the asset folder needs to flat, no sub directories (on desktop).