1

Please explain to me where I am going wrong. Here is my code. I have been trying to load a level I designed in tile in LibGDX, but have been hit with

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

Here is my TileTest.java file

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(); 
    }
}

My file level_1_better.tmx is in the assets folder's root directory. And hyptosis_tile-art-batch-1.png is the sprite sheet it is referencing to create the tile level.

rachit_verma
  • 301
  • 1
  • 3
  • 8

1 Answers1

1

It's because something referenced by your level_1_better.tmx file cannot be found.

That can, for example, be the tile-set and/or the images that make up the tile-set. If you open the .tmx-file you'll see that it references other files, you might see a line similar to this:

<tileset firstgid="1" source="terrain.tsx"/>

If the terrain.tsx file cannot be found by the AssetManager you get the error message you're seeing. If you open the .tsx file it might have references to image files, for example like this:

<image source="terrain.png" width="396" height="198"/>

That image file must also be available to the AssetManager.

When using Tiled to create .tmx files resources will be referenced with relative paths, you need to make sure they're structured and placed correctly in the assets folder.

bornander
  • 751
  • 8
  • 20
  • Thanks man, turns out I didnt have the level_1_better.tsx in the same folder as the tmx file. After I added it there, it all worked out – rachit_verma Aug 22 '20 at 17:50