The Gdx.files.internal("path")
looks into the sourcefolders in your jar. On Android this sourcefolder is, like @BennX said the asset
folder and as much as i know it has to be that folder. On Desktop you can have your own folder, but you need to mark it as source folder in Eclipse.
So if your Projectstructure is like: asset/textures/mario.png you have to call Gdx.files.internal("textures/mario.png");
.
Using Eclipse and libgdx, it cant 'find' and 'load' my png image
Question
i am new to computer programming, and i am following a Android Game Development. I'm on Tutorial Android Game Development in Java - Part 3: Processing Input, and in the first five minutes he has you put a png file into the assets/data folder in the "Tutorial-android" directory. I did so, and followed him. He successfully loaded the picture of mario, i cant. i copied his exact code,
package com.me.tutorial;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
public class Tutorial implements ApplicationListener {
;
SpriteBatch batch;
Texture mario;
Vector2 position;
@Override
public void create() {
batch = new SpriteBatch();
mario = new Texture(Gdx.files.internal("mario.png"));
position = new Vector2(50,50);
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(mario, position.x, position.y);
batch.end();
}
i got these errors
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: mario.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:142)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:104)
at com.me.tutorial.Tutorial.create(Tutorial.java:19)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:137)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:115)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: mario.png (Internal) at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:134) at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218) at com.badlogic.gdx.graphics.Pixmap. (Pixmap.java:137) ... 8 more
i looked and i cannot find a way to solve this. please help me, Thank you.
Solution 2
OTHER TIPS
If it's in the asset/data
folder you need to change the loading line to:
mario=new Texture(Gdx.files.internal("data/mario.png");
The internal looks into the asset
folder not into the asset/data
folder.
Thank you for the answers. i did the Gdx.files.internal("data/mario")
and i ran it and the picture of mario came up like it did before, but when i add
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Keys.W));{
position.y += 1f;
}
if(Gdx.input.isKeyPressed(Keys.A));{
position.x -= 1f;
}
if(Gdx.input.isKeyPressed(Keys.S));{
position.y -= 1f;
}
if(Gdx.input.isKeyPressed(Keys.D));{
position.x += 1f;
}
batch.begin();
batch.draw(mario, position.x, position.y);
batch.end();
}
` the "input" doesn't work when i loaded it. it loads the picture. but it does not move the image when i press W,A,S,D. just like theLazyTryhard did in his video.