1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| loadRemoteTileMaps(tmxNames, dir, callback){ let _t = 0; for (const tmxName of tmxNames) { if(this.tiledMapAssetMaps[tmxName]){ // 判断是否已经加载过了 _t++; if (_t === tmxNames.length) { callback(true, 100); continue; } callback(false, 100 * (_t / tmxNames.length)); continue; } let url = this.baseUrl + "/" + tmxName + ".tmx"; cc.log(url); cc.loader.load( url, (err, assets) => { _t++; if (err) return; let _mapAsset:cc.TiledMapAsset = new cc.TiledMapAsset(); // @ts-ignore _mapAsset.tmxXmlStr = assets; // 缓存到map中 this.tiledMapAssetMaps[tmxName] = _mapAsset; if (_t === tmxNames.length) return callback(true, 100); callback(false, 100 * (_t / tmxNames.length)); }) } }
|