简体   繁体   English

LibGDX Tiled:将贴图映射为2D数组

[英]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). 我正在使用Tiled(.tmx)中的tilemap,在其上移动的玩家被锁定在tile上(因此,他不能在两个tile之间。) 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. 使用Tiled,我在墙上有一个布尔自定义属性,名为can_pass = false,并且我假设我将能够以某种方式访问​​此属性。 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. 我想当我导入它时,它将是一个2D数组或类似的数组,但到目前为止(在大量Google搜索之后),我无法找到如何访问特定图块的方法。 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. 如果我的tilemap可以是2D数组,那将是最好的选择,但是我可以从特定的tile获取属性的任何其他方式都将有所帮助。

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) 然后在X x Y坐标(列,行)上获取像元(〜tile)

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

Everything this and more is in wiki of libGDX https://github.com/libgdx/libgdx/wiki/Tile-maps 所有这些以及更多内容都在libGDX的Wiki中https://github.com/libgdx/libgdx/wiki/Tile-maps

Read it first, before posting a questions. 在发布问题之前,请先阅读它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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