简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM