微信小游戏真机载入TiledMap失败

微信开发者工具模拟器可以载入,真机载入失败,真机使用的资源是按照文档上传到一个http服务处,并设置了wxDownloader.REMOTE_SERVER_ROOT 。其他资源都没问题,就是TiledMap载入失败。
TiledMap的tmx和png无论是否放在resources下面都一样,测试方法是直接在场景里面创建一个TiledMap对象并关联上tmx。

部分错误log:
gameThirdScriptError
Cannot read property ‘getAttribute’ of undefined;at setTimeout callback function
TypeError: Cannot read property ‘getAttribute’ of undefined
at TheClass.parseXMLFile (https://servicewechat.qq.com/game.js:49701:35)
at TheClass.parseXMLString (https://servicewechat.qq.com/game.js:49895:21)
at TheClass.initWithXML (https://servicewechat.qq.com/game.js:49659:21)
at TheClass.ctor (https://servicewechat.qq.com/game.js:49536:40)
at new TheClass (https://servicewechat.qq.com/game.js:32897:16)
at TheClass.initWithXML (https://servicewechat.qq.com/game.js:48982:23)
at CCClass._applyFile (https://servicewechat.qq.com/game.js:50492:28)
at CCClass._initSgNode (https://servicewechat.qq.com/game.js:50281:14)
at CCClass.__preload

我在真机上测试了一下cocossamples,tilemap那个测试用例也报错了:

gameThirdScriptError
Cannot read property ‘getElementsByTagName’ of undefined;at setTimeout callback function
TypeError: Cannot read property ‘getElementsByTagName’ of undefined
at n (https://servicewechat.qq.com/game.js:3:976030)
at e.parseXMLFile (https://servicewechat.qq.com/game.js:3:981531)
at e.parseXMLString (https://servicewechat.qq.com/game.js:3:986823)
at e.initWithXML (https://servicewechat.qq.com/game.js:3:980353)
at e.ctor (https://servicewechat.qq.com/game.js:3:978090)
at new e (https://servicewechat.qq.com/game.js:3:639134)
at e.initWithXML (https://servicewechat.qq.com/game.js:3:966736)
at e._applyFile (https://servicewechat.qq.com/game.js:3:998646)
at e.set [as tmxAsset] (https://servicewechat.qq.com/game.js:3:992216)
at e.onCreateTileMap (https://servicewechat.qq.com/game.js:30

@jare @panda

我又创建了一个测试工程,将cocossamples里面的Dynamic-Tiledmap相关资源放进去,然后整个包大小小于4M,导出到微信小游戏后,在微信开发者工具模拟器上还是可以正常运行,在真机上还是和上面一样的错误。
这说明这个bug和资源下载没关系。
@wangzhe

1赞

经过进一步调试,应该是真机上解析xml有问题, getElementsByTagName函数返回的properties有问题:

function getPropertyList(node) {
var res = [];
if (typeof (node) == “undefined”) {
cc.log(“node is undefined”)
}
var properties = node.getElementsByTagName(“properties”);

  for (var i = 0; i < properties.length; ++i) {
    if (typeof (properties[i]) == "undefined") {
      cc.log("properties[i] is undefined. i="+i);
      continue;
    }
    var property = properties[i].getElementsByTagName("property");
    for (var j = 0; j < property.length; ++j) res.push(property[j]);
  }
  return res.length ? res : null;
}

官方会修复吗?我刚刚也测试到了,而且 只有远程的tmx资源会有问题

@panda @jare 有办法解决吗

我也碰到了相同的问题,模拟器可以,真机上加载tmx文件出错,求官方解决

请问你碰到这个问题使用的引擎是cocos2d-js还是cocosCreator?

以前遇到过类似的问题是因为图块资源tsx文件被微信开发者工具忽略了没有上传

问题定位:libs/xmldom/dom.js的copy方法使用的是for in,在LiveNodeList._updateLiveList中使用了该方法拷贝Array,数组元素都没有拷贝过去,最终结果是是赋值了length,但list中都是undefined。

解决方案:修改文件/Applications/CocosCreator.app/Contents/Resources/static/build-templates/wx/libs/xmldom/dom.js中第127行copy(ls,list)这一句,改用for来拷贝
for(var i = 0; i < ls.length; i++) {
list[i] = ls[i];
}

3赞

按照你的方法修改后已经可以真机上跑tiled 测试了。非常感谢。强行解释一波,对于windows的修改路径就是cocos creator 安装路径/Resources/static/build-templates/wx/libs/xmldom/dom.js

1赞

那请问你这个图块资源被忽略上传解决了没有?

解决了,创建图块的时候有一个选项是“嵌入地图”,把这个勾上就不会额外生成tsx文件了

我这样改了之后微信预览真机报异常。一个图片资源没有上传“忽略上传的文件”。请问你们有这个问题吗?

是不是资源文件夹下最后一张图会忽略上传?

这个问题现在最新的1.9.3官方给解决了吗?之前因为这个问题,放弃了一个项目。现在新项目又得用tiled map了,逃不过啊。。。。
@jare

不确定是tilemap组件导致的问题,麻烦上传下demo,我分析一下,应该是可以解决的问题。

不用另外做demo了,cocossample工程里面的tilemap例子就可以,注意是小游戏环境真机测试不行,模拟器没问题
@huanxinyin

我验证一下!

我这边对tilemap的Puzzle示例做了测试,正常运行,并没有报错,不清楚你的问题。