Trouble loading .png file using LibGDX Gdx.files.internal

拜拜、爱过 提交于 2019-12-04 05:13:35

Solving the "Couldn't load file" issue by cleaning the project (Eclipse)

(For this solution is expected that the paths to your image files are correct.)

Sometimes I have this Couldn't load file problem when I add new images to my project. I don't know why, but my Desktop version of my LibGDX game doesn't update the folder Mygame-desktop/bin/data with my new images (which were added to Mygame-android/assets/data) when the project is built. (That is, every time I save a file, Eclipse builds the project, cause I set the option Project > Build Automatically.)

It should work, cause in LibGDX the Desktop and HTML projects have a link to the Android project assets folder. So, I was not suppose to need to copy manually my new images to Mygame-desktop/bin/data.

The solution, on Eclipse, is to clean (menu Project > Clean...) all LibGDX projects you use for your game, then the files in Mygame-android/assets/data will be copied to Mygame-desktop/bin/data properly.

Milixyron

If you're using Gradle, click the left mouse button in package explorer on Aassets -> Gradle -> Refresh All.

That's it =)

create new folder data in the assets folder of the android project and then access the file using Gdx.files.internal("data/tiles.png")

tiles = new Texture(Gdx.files.internal("data/tiles.png"));

aug13

Make a data folder in the assets folder and instead of using

tiles = new Texture(Gdx.files.internal("tiles.png"));

try this:

tiles = new Texture("data/tiles.png");

Click the left mouse button in Package Explorer on Refresh or just F5.

This solved my problem.

I have this issue working in android studio 2 using the current libgdx version. When I save as a png in psp - cs6 and/or cs15 - it can't read it. I can't recall the exact error message, something like io can't read stream. So I tried saving it again in corel paint. Same problem. Then with the simple paint utility packaged with windows. No good. Finally I downloaded paint.net. Now my workflow just involves an extra step. Any png generated with psp, etc., pretty much any png libgdx grumps about, I load into paint.net, hit "save" and I'm good to go.

Not really a solution per se, but gets the job done.

Looks like you're good but I hope this helps someone out there. Marc

S. Entsov

Maybe your PNG profile is not supported by LibGDX.

I set it to sRGB-elle-V2-srgbtrc.icc (with Krita) and now it works.

In Krita go to:

Image > Properties > Profile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!