gpt4 book ai didi

java - 无法加载平铺 map (Libgdx)

转载 作者:行者123 更新时间:2023-11-30 06:00:34 26 4
gpt4 key购买 nike

我尝试过使用不同的平铺 map 并使用 zlib 压缩类型。我在android下的assets文件夹中有png文件和tmx文件。

如果您需要更多信息,我会回复。任何帮助表示赞赏。谢谢

package com.mm.test1;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;

public class TestOne extends ApplicationAdapter {
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;

@Override
public void create () {
map = new TmxMapLoader().load("grass1.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
}

@Override
public void render () {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

renderer.render();
}

@Override
public void dispose () {
map.dispose();
renderer.dispose();
}
}

错误消息如下:

  Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: Downloads/TilesetGrass/TilesetGrass/overworld_tileset_grass.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:149)
at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:96)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:86)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:67)
at com.mm.test1.TestOne.create(TestOne.java:16)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: Downloads\TilesetGrass\TilesetGrass\overworld_tileset_grass.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:146)
... 8 more

最佳答案

问题出在 .tsx (TileSet) 文件中。
进入 .tsx 文件并更改:
<image source="Downloads/TilesetGrass/TilesetGrass/overworld_tileset_grass.png" ... />

<image source="[relative path to your .png from asset folder]" ... />

通过为 TileMap 创建 TileSet,您可能选择了仍在下载文件夹中的 .png,因此您的 TileSet 指向路径:Downloads/TilesetGrass/TilesetGrass/overworld_tileset_grass.png显示在您的错误消息中。

关于java - 无法加载平铺 map (Libgdx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52341452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com