问题描述
请向我解释我要去哪里错了。这是我的代码。我一直试图在LibGDX中加载我在图块中设计的关卡,但是受到了
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: level_1_better.tmx
这是我的TileTest.java文件
package com.mygdx.game.mytile;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
public class TileTest extends ApplicationAdapter {
private TiledMap map;
private TiledMapRenderer renderer;
private OrthographicCamera camera;
private AssetManager manager;
private Integer tileWidth;
private Integer tileHeight;
private Integer mapWidthInTiles;
private Integer mapHeightInTiles;
private int mapWidthInPixels;
private int mapHeightInPixels;
@Override
public void create () {
manager = new AssetManager();
manager.setLoader(TiledMap.class,new TmxMapLoader());
manager.load("level_1_better.tmx",TiledMap.class);
manager.finishLoading();
map = manager.get("level_1_better.tmx",TiledMap.class);
MapProperties properties = map.getProperties();
tileWidth = properties.get("tilewidth",Integer.class);
tileHeight = properties.get("tileheight",Integer.class);
mapWidthInTiles = properties.get("width",Integer.class);
mapHeightInTiles = properties.get("height",Integer.class);
mapWidthInPixels = mapWidthInTiles * tileWidth;
mapHeightInPixels = mapHeightInTiles * tileHeight;
camera = new OrthographicCamera(320.f,180.f);
camera.position.x = mapWidthInPixels * .5f;
camera.position.y = mapHeightInPixels * .35f;
renderer = new OrthogonalTiledMapRenderer(map);
}
@Override
public void render () {
Gdx.gl.glClearColor(.5f,.7f,.9f,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
renderer.setView(camera);
renderer.render();
}
@Override
public void dispose () {
manager.dispose();
}
}
我的文件level_1_better.tmx在资产文件夹的根目录中。 hyptosis_tile-art-batch-1.png是它用来创建图块级别的Sprite表。
解决方法
这是因为找不到您的level_1_better.tmx
文件引用的内容。
例如可以是图块集和/或组成图块集的图像。 如果打开 .tmx 文件,您会看到它引用了其他文件,您可能会看到类似于以下内容的行:
<tileset firstgid="1" source="terrain.tsx"/>
如果terrain.tsx
无法找到AssetManager
文件,您将看到错误消息。
如果打开 .tsx 文件,则它可能具有对图像文件的引用,例如:
<image source="terrain.png" width="396" height="198"/>
该图像文件也必须对AssetManager
可用。
使用 Tiled 创建 .tmx 文件资源时,将使用相对路径引用资源,您需要确保它们的结构正确并放置在{{1 }}文件夹。