From 3a61a2b28894aba336eff36f4e7c4bd466b065d9 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 9 Jan 2017 17:50:47 +0800 Subject: [PATCH] add node.destroyAllChildren --- cocos2d/core/CCNode.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 0bb6984f74..fdaf2db470 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -489,6 +489,24 @@ var Node = cc.Class({ } }, + /** + * !#en + * Destroy all children from the node, and release all their own references to other objects.
+ * Actual destruct operation will delayed until before rendering. + * !#zh + * 销毁所有子节点,并释放所有它们对其它对象的引用。
+ * 实际销毁操作会延迟到当前帧渲染前执行。 + * @method destroyAllChildren + * @example + * node.destroyAllChildren(); + */ + destroyAllChildren: function () { + var children = this._children; + for (var i = 0; i < children.length; ++i) { + children[i].destroy(); + } + }, + _onPreDestroy: function () { var i, len;