diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index 2d054546a6..726d1aa0dc 100644 --- a/cocos2d/tilemap/CCTiledMap.js +++ b/cocos2d/tilemap/CCTiledMap.js @@ -443,7 +443,7 @@ var TiledMap = cc.Class({ this.node.on('anchor-changed', this._anchorChanged, this); this.node.on('child-added', this._childAdded, this); - this.node.on('child-reorder', this._reorderChildren, this); + this.node.on('child-reorder', this._syncChildrenOrder, this); }, onDisable: function () { @@ -458,7 +458,7 @@ var TiledMap = cc.Class({ this.node.off('anchor-changed', this._anchorChanged, this); this.node.off('child-added', this._childAdded, this); - this.node.off('child-reorder', this._reorderChildren, this); + this.node.off('child-reorder', this._syncChildrenOrder, this); }, onDestroy: function() { @@ -642,7 +642,7 @@ var TiledMap = cc.Class({ } // reorder the children - this._reorderChildren(); + this._syncChildrenOrder(); }, _anchorChanged: function() { @@ -672,21 +672,18 @@ var TiledMap = cc.Class({ } }, - _reorderChildren: function() { + _syncChildrenOrder: function() { var logicChildren = this.node.children; for (var i = 0, n = logicChildren.length; i < n; i++) { var child = logicChildren[i]; var tmxLayer = child.getComponent(cc.TiledLayer); var zOrderValue = child.getSiblingIndex(); - child.setLocalZOrder(zOrderValue); - if (tmxLayer) { - if (tmxLayer._sgNode) { - tmxLayer._sgNode.setLocalZOrder(zOrderValue); - } - } else { - if (child._sgNode) { - child._sgNode.setLocalZOrder(zOrderValue); - } + if (tmxLayer && tmxLayer._sgNode) { + tmxLayer._sgNode.setLocalZOrder(zOrderValue); + } + + if (child._sgNode) { + child._sgNode.setLocalZOrder(zOrderValue); } } },