Java上传png格式无法显示,java – 使用LibGDX Gdx.files.internal加载.png文件时遇到问题...

我正在尝试将纹理加载到libGDX,并且我找到了一个未找到文件的异常.

这是尝试加载.png文件的代码.

//Textures

private Texture tiles;

private TextureRegion grassImage;

private TextureRegion dirtImage;

private TextureRegion stoneImage;

//Entities

private Texture entities;

private TextureRegion playerImage;

public WorldRenderer(World world, boolean debug) {

this.world = world;

this.camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);

this.camera.position.set(CAMERA_WIDTH/2f, CAMERA_HEIGHT/2f, 0);

this.camera.update();

this.debug = debug;

spriteBatch = new SpriteBatch();

loadTextures();

}

public void loadTextures() {

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

grassImage = new TextureRegion(tiles, 0, 0, 32, 32);

dirtImage = new TextureRegion(tiles, 0, 64, 32, 32);

stoneImage = new TextureRegion(tiles, 64, 0, 32, 32);

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

playerImage = new TextureRegion(entities, 0, 0, 32, 32);

}

public void render() {

spriteBatch.begin();

drawGrass();

drawDirt();

drawStone();

drawPlayer();

spriteBatch.end();

if (debug) {

drawDebug();

}

}

这是错误消息:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: tiles.png

at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:140)

at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)

at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)

at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)

at com.badlogic.gdx.graphics.Texture.(Texture.java:133)

at com.badlogic.gdx.graphics.Texture.(Texture.java:122)

at com.mr.zen.level.WorldRenderer.loadTextures(WorldRenderer.java:62)

at com.mr.zen.level.WorldRenderer.(WorldRenderer.java:58)

at com.mr.zen.screens.GameScreen.show(GameScreen.java:29)

at com.badlogic.gdx.Game.setScreen(Game.java:62)

at com.mr.zen.Zen.create(Zen.java:12)

at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)

at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: tiles.png (Internal)

at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:132)

at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:586)

at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)

at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:137)

... 12 more

loadTextures()方法中存在问题.找不到该文件

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

我已经确保将.png文件放在android项目文件的assets文件夹中.我不知道造成这种情况的原因;我已经把它用于其他项目,但这次出现了问题.谢谢你的帮助.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值