3a2c0e82-eeb2-4b16-8e2d-5f12eb27e3ee.js
2.34 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
cc._RF.push(module, '3a2c06C7rJLFo4tXxLrJ+Pu', 'MapManager');
// scripts/kernel/battle/map/MapManager.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapManager = void 0;
var MapData_1 = require("./MapData");
var MapView_1 = require("./MapView");
var MapManager = /** @class */ (function () {
function MapManager() {
this._cache = new Map();
}
Object.defineProperty(MapManager, "ins", {
get: function () {
if (this._ins == null) {
this._ins = new MapManager();
}
return this._ins;
},
enumerable: false,
configurable: true
});
/**
*
* @param mapFileName
* @param finishCallBack 加载完毕回调,参数 data:MapData
* @param thisObj
*/
MapManager.prototype.loadMap = function (mapFileName, finishCallBack, thisObj) {
var _this = this;
var mapUrl = "map/" + mapFileName;
if (this._cache.has(mapUrl)) {
finishCallBack.call(thisObj, this._cache.get(mapUrl).clone());
}
else {
cc.resources.load(mapUrl, cc.TiledMapAsset, function (error, assets) {
if (!error) {
var mapNode = new cc.Node('tiledmapNode:' + mapUrl);
var tiled = mapNode.addComponent(cc.TiledMap);
tiled.tmxAsset = assets;
var data = new MapData_1.MapData();
data.init(tiled);
_this._cache.set(mapUrl, data);
// cc.resources.release(mapUrl, cc.TiledMapAsset); //释放资源,只保留mapData数据 //释放后每次加载新地图都会把图集再加载一次,先不释放
finishCallBack.call(thisObj, data.clone());
}
else {
cc.error(error.message);
}
});
}
};
/**传入数据,产生一个显示对象 */
MapManager.prototype.renderMap = function (data, prefabCollection, preview) {
if (preview === void 0) { preview = false; }
var view = new MapView_1.MapView('mapView_' + data.id.toString());
view.init(data, prefabCollection, preview);
return view;
};
MapManager._ins = null;
return MapManager;
}());
exports.MapManager = MapManager;
cc._RF.pop();