abaratham
abaratham

Reputation: 455

Creating a Pixmap in LibGDX can't find file

This code keeps throwing io.FileNotFoundException:

spriteBatch = new SpriteBatch();
spriteMap = new Texture(new Pixmap(new FileHandle("Sprites.png")));
spriteMap.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.MipMapLinearNearest);
spriteMap.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
sprites = new TextureRegion(spriteMap).split(16, 16);

any ideas what's wrong? i have also tried spriteMap = new Texture(new Pixmap(Gdx.files.internal("Sprites.png"))); but no luck...Sprites.png is just right in the package this class is in

Upvotes: 2

Views: 649

Answers (1)

Daahrien
Daahrien

Reputation: 10320

While using this:

spriteMap = new Texture(new Pixmap(Gdx.files.internal("Sprites.png")));

be totally sure you have a file called "Sprites.png" (with the capital 'S') inside your assets folder.

assets/Sprites.png

If you have a folder between, for example data (created with the Libgdx-setup-ui by default). then you would need to put it aswell.

assets/data/Sprites.png

If you are sure the file is there. Then:

  • If running from eclipse, refresh your project (f5), it may be unsynchronized)
  • If this only happens in the Desktop project, then maybe your assets folder is not correctly linked.

Edit:

You edited your question :p

Sprites.png is just right in the package this class is in

thats your problem, Gdx.files.internal looks into the Android assets folder. not the folder in which the class is in.

Upvotes: 3

Related Questions