问题
In the old libgdx map api, they used to have
map = TiledLoader.createMap(Gdx.files.internal("maps/testmap.tmx"));
atlas = new TileAtlas(map, Gdx.files.internal("maps"));
tileMapRenderer = new TileMapRenderer(map, atlas, 8, 8);
However in the new libgdx the rule changes, to load a tilemap there is no longer needed to use map packer first. You can directly use the .tmx file with the tileset png. Something like following will work, and then call render.
TiledMap map = new TmxMapLoader().load("maps/testmap.tmx");
My question is the original tileselt.png that used to generate the .tmx file, it's size is not power of two. So I still have to either use Texture packer or a map packer to pack it for using.
I could not successfully associate the packed file with the .tmx;
Is there anyway to approach this issue?
Thanks
回答1:
If you target GLES 1.0, you will need power-of-two tilesets. Some devices might allow non-power-of-two with GLES 1.0, but that isn't guaranteed. With GLES 2.0 this restriction is lifted, but you still might get better performance out of power-of-two.
You can still use the TiledMapPacker-produced maps, you will just need to load the map with AtlasTmxMapLoader
instead of TmxMapLoader
.
回答2:
They do not need to be power of two. If you have Problems with it like you get the power of two error set Texture.setEnforcePotImages(false);
inside of your MainClass.
You do not need the packer anymore so i think you cant associate the packer to the tmx file.
If you use the TmxMapLoader
the tilesets need to be inside of the same folder of the .tmx
file.
If they are inside of an different directory you need to configure the source path inside of the .tmx
file. here is an Example:
<tileset firstgid="257" name="mountain" tilewidth="32" tileheight="32">
<image source="mountain.png" width="512" height="512"/>
</tileset>
is the regular output of Tiled. If the Tileset is inside of for example config it you need to change it like this:
<tileset firstgid="257" name="mountain" tilewidth="32" tileheight="32">
<image source="config/mountain.png" width="512" height="512"/>
</tileset>
But it still need to be a subfolder of the path where the tmx file is.
Regards hope that may helps.
来源:https://stackoverflow.com/questions/18397256/tmxmaploader-to-use-packed-tileset