[]TiledMap加载报错 relativePath为空


QQ图片20180326214401.png

如图,加载tiledmap是一直报错这个。relativePath应该是json文件中png的位置吧,我明明有定义,但是为啥加载不到呢
var TiledMap = Laya.TiledMap;
var Rectangle = Laya.Rectangle;
var Handler = Laya.Handler;
var Sprite = Laya.Sprite;
var MapLayer = Laya.MapLayer;

Laya.init(800, 800);

var map1 = new TiledMap();
map1.createMap("res/maps/scence1.json",new Rectangle(0,0,800, 800),Handler.create(this,onMapLoaded));

function onMapLoaded(){
console.log("地图加载完成");
}
scence1.json
{ "height":25,
"infinite":false,
"layers":[
{
"data":[7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 1, 1, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":25,
"name":"\u5757\u5c42 2",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":25,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 206, 206, 206, 206, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 206, 206, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 139, 140, 0, 0, 0, 0, 3221225508, 3221225498, 2684354595, 2684354595, 39, 39, 18, 3221225509, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 151, 152, 0, 0, 35, 18, 18, 18, 18, 18, 18, 18, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 0, 0, 159, 160, 0, 0, 35, 18, 25, 26, 27, 18, 18, 18, 3221225519, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 18, 33, 164, 35, 18, 40, 18, 3221225519, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 18, 41, 42, 43, 18, 18, 18, 3221225519, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 18, 18, 18, 18, 18, 18, 18, 1610612773, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1610612778, 18, 18, 18, 3221225511, 18, 18, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3221225516, 37, 36, 0, 164, 37, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 508, 509, 510, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 516, 517, 518, 0, 0, 0, 0, 0, 0, 197, 198, 199, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 524, 525, 526, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 508, 509, 510, 508, 509, 510, 0, 0, 0, 0, 0, 0, 0, 0, 198, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 516, 517, 518, 516, 517, 518, 0, 0, 0, 0, 0, 0, 0, 198, 206, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 524, 525, 526, 524, 525, 526, 0, 0, 0, 0, 0, 0, 0, 206, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":25,
"name":"\u5757\u5c42 1",
"opacity":1,
"properties":
{
"isCanPass":"0"
},
"propertytypes":
{
"isCanPass":"string"
},
"type":"tilelayer",
"visible":true,
"width":25,
"x":0,
"y":0
}],
"nextobjectid":1,
"orientation":"orthogonal",
"properties":
{
"isCanPass":"1"
},
"propertytypes":
{
"isCanPass":"string"
},
"renderorder":"right-down",
"tiledversion":"1.1.3",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"daditu.tsx"
},
{
"columns":8,
"firstgid":1201,
"image":"daditu.png",
"imageheight":4800,
"imagewidth":256,
"margin":0,
"name":" daditu",
"spacing":0,
"tilecount":1200,
"tileheight":32,
"tilewidth":32
}],
"tilewidth":32,
"type":"map",
"version":1,
"width":25
}
已邀请:

mtjss2

赞同来自:

自己看源码解决了,问题在于我用的tiledmap在生成json文件时"tilesets"属性那里还有一个包含tsx的对象
   {
"firstgid":1,
"source":"daditu.tsx"
},
就是这段,而laya.tiledmap.js的源码中是这样的

var tArray=tJsonData.tilesets;
for (i=0;i < tArray.length;i++){
tileset=tArray[i];
tTileSet=new TileSet();
tTileSet.init(tileset);
if (tTileSet.properties && tTileSet.properties.ignore)continue ;
this._tileProperties[i]=tTileSet.tileproperties;
this.addTileProperties(tTileSet.tileproperties);
this._tileSetArray.push(tTileSet);
直接取了那个对象,并默认里面有image属性,所以保存了。解决办法就是把那个不知道干嘛用的对象删掉

要回复问题请先

商务合作
商务合作