XMXtiledmap getLayer()与cocos2dx中的tmx文件一起返回null [英] XMXtiledmap getLayer() return null with tmx file in cocos2dx

查看:59
本文介绍了XMXtiledmap getLayer()与cocos2dx中的tmx文件一起返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用平铺的地图编辑器来获取 tmx 文件并将其加载到使用cocos2d-x c ++ 3.15.1版开发的游戏中

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

这是tmx文件:

 <?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));

我可以确认 tmap 已成功加载,但是 layer null ,并检查了调试器中的局部变量.

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

我尝试了不同的 tmx 格式,例如 xml base64 ,但是它们都给出了一些结果.

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

我做错了什么?

推荐答案

我发现,不仅我应该将tmx文件放在源文件夹中,而且还必须将tileet文件tsx文件导入同一文件夹中,以及我作为tileet文件加载的图像.但是cocos2dx给出的错误消息可能会误导该解决方案.不好的是我没有完全了解平铺的地图.

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.

这篇关于XMXtiledmap getLayer()与cocos2dx中的tmx文件一起返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆