在LibGDX,Java中使用AssetManager加载资源

时间:2016-05-06 12:36:19

标签: java libgdx

我遇到一些libgdx java代码的问题。 我正在使用assetmanager来加载一些纹理。 文件在android项目中,在assets / data文件夹中,但是当我尝试像这样加载它们时:

manager.load("data/tile1.jpg", Texture.class);

它抛出异常,基本上是这样的:

Couldn't load dependencies of asset: data/tile1.jpg

有人可以帮忙吗?

编辑: 我发布了完整的异常:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: data/tile1.jpg
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:570)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:375)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:396)
at com.cyanstudios.onlinerpg.Game.create(Game.java:36)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: data/tile1.jpg
    at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:121)
    at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:90)
    at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:498)
    at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:373)
    ... 4 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/tile1.jpg
    at com.badlogic.gdx.utils.async.AsyncResult.get(AsyncResult.java:46)
    at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:119)
    ... 7 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/tile1.jpg
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
    at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
    at com.badlogic.gdx.assets.loaders.TextureLoader.loadAsync(TextureLoader.java:69)
    at com.badlogic.gdx.assets.loaders.TextureLoader.loadAsync(TextureLoader.java:41)
    at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:70)
    at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:34)
    at com.badlogic.gdx.utils.async.AsyncExecutor$2.call(AsyncExecutor.java:58)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data\tile1.jpg (Internal)
    at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
    at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:145)
    ... 10 more

1 个答案:

答案 0 :(得分:1)

当您使用Eclipse时,请确保将资产文件夹声明为项目属性中的源文件夹。