mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 11:31:59 +08:00
fixed tiledmap anchor point
This commit is contained in:
@@ -428,6 +428,12 @@ let TiledMap = cc.Class({
|
||||
// refresh layer entities
|
||||
this._applyFile();
|
||||
}
|
||||
|
||||
this.node.on('anchor-changed', this._syncAnchorPoint, this);
|
||||
},
|
||||
|
||||
onDisable () {
|
||||
this.node.off('anchor-changed', this._syncAnchorPoint, this);
|
||||
},
|
||||
|
||||
_applyFile () {
|
||||
@@ -459,6 +465,13 @@ let TiledMap = cc.Class({
|
||||
this._buildWithMapInfo(mapInfo);
|
||||
}
|
||||
},
|
||||
|
||||
_syncAnchorPoint () {
|
||||
let anchor = this.node.getAnchorPoint();
|
||||
for (let i = 0, l = this._layers.length; i < l; i++) {
|
||||
this._layers[i].node.setAnchorPoint(anchor);
|
||||
}
|
||||
},
|
||||
|
||||
_buildWithMapInfo (mapInfo) {
|
||||
this._mapSize = mapInfo.getMapSize();
|
||||
@@ -491,7 +504,6 @@ let TiledMap = cc.Class({
|
||||
if (!child) {
|
||||
child = new cc.Node();
|
||||
child.name = name;
|
||||
child.setAnchorPoint(0.5, 0.5);
|
||||
|
||||
node.addChild(child);
|
||||
}
|
||||
@@ -509,8 +521,8 @@ let TiledMap = cc.Class({
|
||||
layerInfo.ownTiles = false;
|
||||
|
||||
// update content size with the max size
|
||||
this.width = Math.max(this.width, child.width);
|
||||
this.height = Math.max(this.height, child.height);
|
||||
this.node.width = Math.max(this.node.width, child.width);
|
||||
this.node.height = Math.max(this.node.height, child.height);
|
||||
|
||||
layers.push(layer);
|
||||
}
|
||||
@@ -525,17 +537,8 @@ let TiledMap = cc.Class({
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_parseLayer (layerInfo, mapInfo) {
|
||||
let node = new cc.Node();
|
||||
let layer = node.addComponent(cc.TiledLayer);
|
||||
let tileset = this._tilesetForLayer(layerInfo, mapInfo);
|
||||
// tell the layerinfo to release the ownership of the tiles map.
|
||||
layer.init(tileset, layerInfo, mapInfo);
|
||||
layerInfo.ownTiles = false;
|
||||
|
||||
return node;
|
||||
this._syncAnchorPoint();
|
||||
},
|
||||
|
||||
_tilesetForLayer (layerInfo, mapInfo) {
|
||||
|
||||
Reference in New Issue
Block a user