java - NullPointerException Libgdx -
i've seen questions similar this, none match i'm experiencing libgdx project (desktop only). i've made .tmx map using tiled , copied assets folder, has 2 subpackages: gamescreens (with maps) , tiles. if open .tmx map eclipse using tiled works fine. here's .tmx:
<?xml version="1.0" encoding="utf-8"?> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="8" height="8" tilewidth="32" tileheight="32"> <tileset firstgid="1" name="default" tilewidth="32" tileheight="32"> <tile id="0"> <image width="32" height="32" source="../tiles/rock.png"/> </tile> <tile id="1"> <image width="32" height="32" source="../tiles/tile_default_1.jpg"/> </tile> <tile id="2"> <image width="32" height="32" source="../tiles/tile_default_2.jpg"/> </tile> <tile id="3"> <image width="32" height="32" source="../tiles/wall.png"/> </tile> </tileset> <layer name="camada de tiles 1" width="8" height="8"> <data encoding="base64" compression="gzip"> ejxjywbgycgamxfgzhlgjhfglpku8okxh5f78geabraa2q== </data> </layer> </map>
i created abstract class gamestate:
package com.mygdx.cavedive.game.gamestates; //imports public abstract class gamestate { private static tmxmaploader maploader = new tmxmaploader(); protected static orthogonaltiledmaprenderer otmr; protected static orthographiccamera cam; protected orthogonaltiledmaprenderer getrenderer() { return otmr; } protected tmxmaploader getmaploader() { return maploader; } protected void disposerenderer() { otmr.dispose(); } }
and class extends it:
package com.mygdx.cavedive.game.gamestates; //imports public class level_1 extends gamestate implements screen { private tiledmap map; @override public void render(float delta) { //clear screen gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); otmr.setview(cam); //render screen otmr.render(); } @override public void resize(int width, int height) { cam.viewportwidth = width; cam.viewportheight = height; cam.update(); } @override public void show() { map = getmaploader().load("gamescreens/level1.tmx"); otmr = new orthogonaltiledmaprenderer(map, 1f / 32f); cam = new orthographiccamera(); } @override public void hide() { dispose(); } @override public void pause() { } @override public void resume() { } @override public void dispose() { disposerenderer(); map.dispose(); } }
now here's get:
exception in thread "lwjgl application" java.lang.nullpointerexception @ com.badlogic.gdx.maps.tiled.tmxmaploader.loadtilesets(tmxmaploader.java:246) @ com.badlogic.gdx.maps.tiled.tmxmaploader.load(tmxmaploader.java:118) @ com.badlogic.gdx.maps.tiled.tmxmaploader.load(tmxmaploader.java:104) @ com.mygdx.cavedive.game.gamestates.level_1.show(level_1.java:40) @ com.badlogic.gdx.game.setscreen(game.java:61) @ com.mygdx.cavedive.game.app.gamecore.create(gamecore.java:28) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication.mainloop(lwjglapplication.java:136) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication$1.run(lwjglapplication.java:114)
it has tilesets, can't figure out what.
the "image collection" tileset each tile refers own image new feature in tiled 0.10. version of libgdx you're using not support these kind of tilesets yet.
according this issue on github, libgdx nightlies support feature.
Comments
Post a Comment