XMXtiledmap getLayer() return null with tmx file in cocos2dx

南笙酒味 提交于 2019-12-12 04:04:20

问题


I am using tiled map editor to get a tmx file and loaded that into my game which is developed with cocos2d-x c++ version 3.15.1

Here is the tmx file:

 <?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.0.2" orientation="orthogonal" renderorder="right-down" width="7" height="7" tilewidth="100" tileheight="100" nextobjectid="1">
 <tileset firstgid="1" source="map.tsx"/>
 <layer name="gamemap" width="7" height="7">
  <data encoding="csv">
2,2,1,2,2,2,1,
2,2,2,2,2,1,1,
1,1,1,1,2,1,1,
1,1,2,1,1,2,1,
1,2,2,2,2,2,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1
</data>
 </layer>
</map>

And I use that with following code:

auto tmap = TMXTiledMap::create("map/map.tmx");
auto layer = tmap->getLayer("gamemap"); //null here
auto size = tmap->getMapSize(); 
CCLOG(" %f, %f", size.height, size.width);
auto sprite = layer->getTileAt(Vec2(1, 1));

I can confirm that tmap was loaded successfully, but layer is null with inspect to the local variables in the debugger.

I have tried different tmx format such as xml and base64 but they all give some result.

What have I done wrong?


回答1:


I have found this out that not only I should put the tmx file in the source folder but also I have to import tileset file tsx file in the same folder and as well as the image that I loaded as a tileset file too. but the error message that cocos2dx gives could be a misleading for the solution. My bad to not got tiled map fully understand.



来源:https://stackoverflow.com/questions/45636472/xmxtiledmap-getlayer-return-null-with-tmx-file-in-cocos2dx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!