"File Not Found" When Running New Libgdx Project

File not found when running new LibGDX project

From libgdx wiki

When you run Desktop Project

The application will fail the first time. Open the Run Configuration you just created and set the working directory to the android/assets/ directory!

link your desktop project to android assets folder?

Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab => Working Directory => Others then browse to yourproject-android/assets/ and click Apply => Run

Sample Image

LibGDX, GDX.files.internal() File not found

Okay, I found the trick. For those which encounter the same issue (working on Eclipse but it's pretty the same whatever the IDE is) there is one thread on stack overflow already existing which give additional solutions.
For me I had to set-up the "working directory" (for the desktop main for exemple). To do this go on Run>Run configuration>Arguments and at working directory's section there is Default and Other. Tick Other's box and me I had to write ${workspace_loc:my-gdx-game-core/assets} but I think it works like ${workspace_loc:[name-of-your-core-directory]/assets}. Hope it helped.

Libgdx: File not found error 'Internal' when opening external file

After looking carefully at your stack trace it seems that the model file itself its loading properly.

The problem arises when loading the Textures of the model:

at
com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222) at
com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:137) at
com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at
com.badlogic.gdx.graphics.Texture.(Texture.java:92) at
com.badlogic.gdx.graphics.g3d.utils.TextureProvider$FileTextureProvider.load(TextureProvider.java:34)
at com.badlogic.gdx.graphics.g3d.Model.convertMaterial(Model.java:290)
at com.badlogic.gdx.graphics.g3d.Model.loadMaterials(Model.java:266)

I believe libGDX is trying to load the texture files from the wrong location (an internal location, explaining the error you get).

I've never worked with libDGX model functions but I think that you should use this method instead: loadModel(FileHandle fileHandle, TextureProvider textureProvider)

and pass in a TextureProvider that loads the Texture file from an external folder. (and make sure the texture file is there).

Should be easy to implement a custom TextureProvider that does exactly that, by looking at the FileTextureProvider.

libgdx -- Gdx.files.internal(); -- File Not Found

Try "cleaning" your project by going to Project-> Clean. Also try "refreshing" your libGDX desktop folder by right clicking and using Gradle-> Refresh All

libGDX uses linked folders. You only need to copy the file to one of your asset folders (do this in eclipse, not in file explorer.)

LibGDX could not parse tmx file: file not found

I've got it sorted out:

First issue - map not found

Fix: put the files inside the desktop folder of the project, not inside assets.

Using Gdx.files.internal("map.tmx").file().getAbsolutePath(); you can print the location you need to use.

Second issue - GL30 error

Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Error compiling shader: Vertex shader failed to compile with the following errors: ERROR: error(#272) Implicit version number 110 not supported by GL3 forward compatible context ERROR: error(#273) 1 compilation errors. No code generated

Fix: copy the default shader and add #version 330 as the first string to be written. The default shader can be found through the error printed in the console, you'll se GDX by default uses a very old version.

This is how my default shader looks like:

static public ShaderProgram createDefaultShader () {
String vertexShader = "#version 330 core\n"
+ "in vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
+ "in vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
+ "in vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
+ "uniform mat4 u_projTrans;\n" //
+ "out vec4 v_color;\n" //
+ "out vec2 v_texCoords;\n" //
+ "\n" //
+ "void main()\n" //
+ "{\n" //
+ " v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
+ " v_color.a = v_color.a * (255.0/254.0);\n" //
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
+ "}\n";
String fragmentShader = "#version 330 core\n"
+ "#ifdef GL_ES\n" //
+ "#define LOWP lowp\n" //
+ "precision mediump float;\n" //
+ "#else\n" //
+ "#define LOWP \n" //
+ "#endif\n" //
+ "in LOWP vec4 v_color;\n" //
+ "in vec2 v_texCoords;\n" //
+ "out vec4 fragColor;\n" //
+ "uniform sampler2D u_texture;\n" //
+ "void main()\n"//
+ "{\n" //
+ " fragColor = v_color * texture(u_texture, v_texCoords);\n" //
+ "}";
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
return shader;
}

You'll then need to feed it to a Batch object which you'll then use to render the map:

Batch = new SpriteBatch(1000, createDefaultShader()); // not required to be a spriteBatch
IsometricTiledMapRenderer renderer= new IsometricTiledMapRenderer(map,spriteBatch);

Third issue - black/blinking screen

Fix: make sure you've put super.render(); inside the method public void render ()

Otherwise the screen will be black and if you render inside the show() method, you'll obtain a blinking screen.

Hope this helps somebody!

LibGDX project can't find assets folder

Probably your assets from the android project is not correctly linked with the desktop project.

Your linked assets folder from inside the desktop project should look like this:
Sample Image

If it doesn't(or it doesn't exists) ,delete the folder(in the desktop project),and go to the the project properties->java build path->source->link source

Sample Image

browse->[select the asset folder inside the android project]->finish

Sample Image



Related Topics



Leave a reply



Submit