hchong
hchong

Reputation: 45

LibGdx Error parsing file

I recently started a new game project through Android Studio and made a tilemap in a software called Tiled. However I keep getting this error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: assets/Desert.tmx
     at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
     at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:77)
     at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:65)
     at com.poptag.game.PopTag.create(PopTag.java:29)
     at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
     at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: assets\Desert.tmx (Internal)
     at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
     at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:163)
     at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:81)
     ... 5 more

And here's code that loads and renders it:

@Override
public void create () {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    camera = new OrthographicCamera();
    camera.setToOrtho(false,w,h);
    camera.update();
    tiledMap = new TmxMapLoader().load("assets/Desert.tmx");
    tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
    Gdx.input.setInputProcessor(this);
}

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();
}

I have put the map "Desert.tmx" and the tileset "tmw_desert_spacing.png" into the assets folder for both Android and Desktop. When I run the launcher for the Desktop, I receive these errors.

Here's the file tree

Upvotes: 0

Views: 3428

Answers (3)

Mayur Lokare
Mayur Lokare

Reputation: 31

If you open the map .tmx file
then you get tag tileset firstgid="1" source="grass_and_water3.tsx"
which is pointing to tileset .tsx file, and even .tsx file pointing to combined tiles image i.e. .png file

In order to solve this problem just keep all file in same location i.e. under asset/ and provide same path in all files (.tmx, .tsx etc)

Upvotes: 0

hchong
hchong

Reputation: 45

Well, I solved the problem. All I had to do was remake a map with Tiled and use a completely new tileset and it finally worked once I loaded the two files.

Upvotes: 2

snyggt
snyggt

Reputation: 9

In your: tiledMap = new Tmxblabla.load(assets/Desert.tmx) Shouldnt you load your file called Tiled here? Otherwise i see no need of you referring to this file since it is not called to in your code.

Upvotes: 0

Related Questions