简体   繁体   中英

LibGDX Tiled: Tile map as 2D array

I'm using a tilemap from Tiled (.tmx) and the player who moves on it is locked to the tiled (so, he can't be somewhere between two tiles). Using Tiled, I have a Boolean custom property on the walls called can_pass = false, and I assumed I would be able to access this property somehow. I thought when I imported it that it would be a 2D array or similar, yet so far (after a lot of google searches), I can't find out how to access a specific tile. Is this possible? It would be best if my tilemap could be a 2D array, but any other way I can get the properties from a specific tile would help.

You can simply load your map by

TiledMap map = new TmxMapLoader().load("yourMap.tmx");

Load specified layer of map

MapLayer layer = map.getLayers().get(0);

and then just get cell (~tile) on X x Y coordinates (column, row)

   Cell cell = tileLayer.getCell(column, row);

Everything this and more is in wiki of libGDX https://github.com/libgdx/libgdx/wiki/Tile-maps

Read it first, before posting a questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM