简体   繁体   English

从LibGdx中的tmx映射(TiledMap)创建Sprite列表

[英]create a Sprite list from a tmx map (TiledMap) in LibGdx

After many search on the internet I cannot find the answer .. 在互联网上搜索了很多之后,我找不到答案了。

What is the situation ? 现在是什么状况 ? I'm a student in computer science at university (in belgium) and i have to make a tower defense in Java with the graphic library LibGdx. 我是比利时大学的计算机科学专业的学生,​​我必须使用图形库LibGdx用Java进行防御塔。

What is the problem ? 问题是什么 ? In LibGdx, there is a map object named "TiledMap". 在LibGdx中,有一个名为“ TiledMap”的地图对象。 It allows to load a tmx map (made with tiled for example..) So i load this map with this code : 它允许加载一个tmx地图(例如,以tile ..制成)。因此,我使用以下代码加载该地图:

TiledMap tiledMap = new TmxMapLoader().load(name);

And i render it with this code : 我用下面的代码渲染它:

TiledMapRenderer tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
OrthographicCamera camera = new OrthographicCamera(960, 900); // Size of map
camera.position.set(posX, posY, 0);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();

But i don't found a method or something that allows me to separate the tmx map on a list of Sprite.. like 但是我没有找到一种方法或其他让我在Sprite列表上分离tmx映射的方法。

"private Sprite[][] tiles" .. this attribute will allow to change a tile at the position (0,0) by the sprite of a tower (if the player wants to build a tower to this position) “ private Sprite [] [] tile” ..此属性将允许通过塔的精灵更改位置(0,0)处的图块(如果玩家想将塔建造到该位置)

and also with properties used to make the tmx map i'll able to do another attribute like 以及用于制作tmx映射的属性,我将能够执行另一个属性,例如

"private boolean[][] isWay" .. to know if the tile (0,0) is the way (monsters can walk only if the tile is way).. “ private boolean [] [] isWay” ..来了解图块(0,0)是否为路(怪物只有在图块为路时才能行走)。

So i don't know how to change the TiledMap to Sprite[][] 所以我不知道如何将TiledMap更改为Sprite [] []

I'm sorry if i do some english mistakes but i try to improve my english everyday... 对不起,如果我在英语方面犯了一些错误,但我每天都在努力提高自己的英语水平。

Thank you for your help ;) 谢谢您的帮助 ;)

TiledMap doesn't have any Sprite instances. TiledMap没有任何Sprite实例。 You can get refererence to a TiledMapTileLayer via TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0) which would get the first layer. 您可以通过TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0)获得对TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0) ,这将获得第一层。

With that, you can get and set the cells (and the tiles they contain) via layer.getCell(x, y) and layer.setCell(x, y, cell) . 这样,您可以通过layer.getCell(x, y)layer.setCell(x, y, cell)获取并设置单元格(以及它们包含的图块layer.setCell(x, y, cell)

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

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