From a6c55e73e52d98f36e73a1044372ec5382d95c06 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 27 May 2016 11:37:27 +0800 Subject: [PATCH 1/2] Solve the issue : Can't reorder the children of TiledMap nodes. --- cocos2d/tilemap/CCTiledMap.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index 2d054546a6..b75b0abf8e 100644 --- a/cocos2d/tilemap/CCTiledMap.js +++ b/cocos2d/tilemap/CCTiledMap.js @@ -678,15 +678,12 @@ var TiledMap = cc.Class({ 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); } } }, From 4453110d095e406ba8670b6286e62dc9c9a95906 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 27 May 2016 11:56:16 +0800 Subject: [PATCH 2/2] Improve the method name. --- cocos2d/tilemap/CCTiledMap.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index b75b0abf8e..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,7 +672,7 @@ 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];