creator 动态远程加载TileMap


creator 动态远程加载TileMap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
loadRemoteTileMaps(tmxNames, dir, callback){
let baseUrl = Common.s_remote_resource_url + "resources/tiledMap/" + dir;
let _t = 0;
for (const tmxName of tmxNames) {
let url = baseUrl + "/" + tmxName + ".tmx";
cc.loader.load( url, (err, assets) => {
_t++;
if (err) return;
let _mapAsset:cc.TiledMapAsset = new cc.TiledMapAsset();
// @ts-ignore
_mapAsset.tmxXmlStr = assets;
this.tiledMapAssetMaps[tmxName] = _mapAsset;
if (_t === tmxNames.length) return callback(true, 100);
callback(false, 100 * (_t / tmxNames.length));
});
}
}