From 4b1014e5c96c84b30a67b6aeec6d21c62dcf4f7b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 23 Dec 2016 13:51:11 +0800 Subject: [PATCH] move globalZorder anchor to CCNode --- cocos2d/core/CCNode.js | 133 ++++++++++++++++++++++++++++++++ cocos2d/core/utils/base-node.js | 133 -------------------------------- 2 files changed, 133 insertions(+), 133 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 88ad45791b..897f999c43 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -2115,6 +2115,139 @@ var Node = cc.Class({ return this._opacityModifyRGB; }, + /* + * !#en + * Defines the oder in which the nodes are renderer. + * Nodes that have a Global Z Order lower, are renderer first. + *
+ * In case two or more nodes have the same Global Z Order, the oder is not guaranteed. + * The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used. + *
+ * By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes. + *
+ * Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order. + *
+ * Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors. + * And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode. + * !#zh + * 定义节点的渲染顺序。 + * 节点具有全局 Z 顺序,顺序越小的节点,最先渲染。 + *
+ * 假设两个或者更多的节点拥有相同的全局 Z 顺序,那么渲染顺序无法保证。 + * 唯一的例外是如果节点的全局 Z 顺序为零,那么场景中的顺序是可以使用默认的。 + *
+ * 所有的节点全局 Z 顺序都是零。这就是说,默认使用场景中的顺序来渲染节点。 + *
+ * 全局 Z 顺序是非常有用的当你需要渲染节点按照不同的顺序而不是场景顺序。 + *
+ * 局限性: 全局 Z 顺序不能够被拥有继承 “SpriteBatchNode” 的节点使用。 + * 并且如果 “ClippingNode” 是其中之一的上代,那么 “global Z order” 将会和 “ClippingNode” 有关。 + * @method setGlobalZOrder + * @param {Number} globalZOrder + * @example + * node.setGlobalZOrder(0); + */ + setGlobalZOrder: function (globalZOrder) { + this._globalZOrder = globalZOrder; + this._sgNode.setGlobalZOrder(globalZOrder); + }, + + /* + * !#en Return the Node's Global Z Order. + * !#zh 获取节点的全局 Z 顺序。 + * @method getGlobalZOrder + * @returns {number} The node's global Z order + * @example + * cc.log("Global Z Order: " + node.getGlobalZOrder()); + */ + getGlobalZOrder: function () { + this._globalZOrder = this._sgNode.getGlobalZOrder(); + return this._globalZOrder; + }, + + /** + * !#en + * Returns a copy of the anchor point.
+ * Anchor point is the point around which all transformations and positioning manipulations take place.
+ * It's like a pin in the node where it is "attached" to its parent.
+ * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
+ * But you can use values higher than (1,1) and lower than (0,0) too.
+ * The default anchor point is (0.5,0.5), so it starts at the center of the node. + * !#zh + * 获取节点锚点,用百分比表示。
+ * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
+ * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
+ * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
+ * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
+ * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。 + * @method getAnchorPoint + * @return {Vec2} The anchor point of node. + * @example + * cc.log("Node AnchorPoint: " + node.getAnchorPoint()); + */ + getAnchorPoint: function () { + return cc.p(this._anchorPoint); + }, + + /** + * !#en + * Sets the anchor point in percent.
+ * anchor point is the point around which all transformations and positioning manipulations take place.
+ * It's like a pin in the node where it is "attached" to its parent.
+ * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
+ * But you can use values higher than (1,1) and lower than (0,0) too.
+ * The default anchor point is (0.5,0.5), so it starts at the center of the node. + * !#zh + * 设置锚点的百分比。
+ * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
+ * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
+ * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
+ * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
+ * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。 + * @method setAnchorPoint + * @param {Vec2|Number} point - The anchor point of node or The x axis anchor of node. + * @param {Number} [y] - The y axis anchor of node. + * @example + * node.setAnchorPoint(cc.v2(1, 1)); + * node.setAnchorPoint(1, 1); + */ + setAnchorPoint: function (point, y) { + var locAnchorPoint = this._anchorPoint; + if (y === undefined) { + if ((point.x === locAnchorPoint.x) && (point.y === locAnchorPoint.y)) + return; + locAnchorPoint.x = point.x; + locAnchorPoint.y = point.y; + } else { + if ((point === locAnchorPoint.x) && (y === locAnchorPoint.y)) + return; + locAnchorPoint.x = point; + locAnchorPoint.y = y; + } + var sizeProvider = this._sizeProvider; + if (sizeProvider instanceof _ccsg.Node) { + sizeProvider.setAnchorPoint(locAnchorPoint); + } + this.emit(ANCHOR_CHANGED); + }, + + /** + * !#en + * Returns a copy of the anchor point in absolute pixels.
+ * you can only read it. If you wish to modify it, use setAnchorPoint. + * !#zh + * 返回锚点的绝对像素位置。
+ * 你只能读它。如果您要修改它,使用 setAnchorPoint。 + * @see cc.Node#getAnchorPoint + * @method getAnchorPointInPoints + * @return {Vec2} The anchor point in absolute pixels. + * @example + * cc.log("AnchorPointInPoints: " + node.getAnchorPointInPoints()); + */ + getAnchorPointInPoints: function () { + return this._sgNode.getAnchorPointInPoints(); + }, + //functions moved from base node end }); diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 66277da361..5e53114e3f 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -367,139 +367,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ } }, - /* - * !#en - * Defines the oder in which the nodes are renderer. - * Nodes that have a Global Z Order lower, are renderer first. - *
- * In case two or more nodes have the same Global Z Order, the oder is not guaranteed. - * The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used. - *
- * By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes. - *
- * Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order. - *
- * Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors. - * And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode. - * !#zh - * 定义节点的渲染顺序。 - * 节点具有全局 Z 顺序,顺序越小的节点,最先渲染。 - *
- * 假设两个或者更多的节点拥有相同的全局 Z 顺序,那么渲染顺序无法保证。 - * 唯一的例外是如果节点的全局 Z 顺序为零,那么场景中的顺序是可以使用默认的。 - *
- * 所有的节点全局 Z 顺序都是零。这就是说,默认使用场景中的顺序来渲染节点。 - *
- * 全局 Z 顺序是非常有用的当你需要渲染节点按照不同的顺序而不是场景顺序。 - *
- * 局限性: 全局 Z 顺序不能够被拥有继承 “SpriteBatchNode” 的节点使用。 - * 并且如果 “ClippingNode” 是其中之一的上代,那么 “global Z order” 将会和 “ClippingNode” 有关。 - * @method setGlobalZOrder - * @param {Number} globalZOrder - * @example - * node.setGlobalZOrder(0); - */ - setGlobalZOrder: function (globalZOrder) { - this._globalZOrder = globalZOrder; - this._sgNode.setGlobalZOrder(globalZOrder); - }, - - /* - * !#en Return the Node's Global Z Order. - * !#zh 获取节点的全局 Z 顺序。 - * @method getGlobalZOrder - * @returns {number} The node's global Z order - * @example - * cc.log("Global Z Order: " + node.getGlobalZOrder()); - */ - getGlobalZOrder: function () { - this._globalZOrder = this._sgNode.getGlobalZOrder(); - return this._globalZOrder; - }, - - /** - * !#en - * Returns a copy of the anchor point.
- * Anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node. - * !#zh - * 获取节点锚点,用百分比表示。
- * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
- * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
- * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
- * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
- * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。 - * @method getAnchorPoint - * @return {Vec2} The anchor point of node. - * @example - * cc.log("Node AnchorPoint: " + node.getAnchorPoint()); - */ - getAnchorPoint: function () { - return cc.p(this._anchorPoint); - }, - - /** - * !#en - * Sets the anchor point in percent.
- * anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node. - * !#zh - * 设置锚点的百分比。
- * 锚点应用于所有变换和坐标点的操作,它就像在节点上连接其父节点的大头针。
- * 锚点是标准化的,就像百分比一样。(0,0) 表示左下角,(1,1) 表示右上角。
- * 但是你可以使用比(1,1)更高的值或者比(0,0)更低的值。
- * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
- * 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。 - * @method setAnchorPoint - * @param {Vec2|Number} point - The anchor point of node or The x axis anchor of node. - * @param {Number} [y] - The y axis anchor of node. - * @example - * node.setAnchorPoint(cc.v2(1, 1)); - * node.setAnchorPoint(1, 1); - */ - setAnchorPoint: function (point, y) { - var locAnchorPoint = this._anchorPoint; - if (y === undefined) { - if ((point.x === locAnchorPoint.x) && (point.y === locAnchorPoint.y)) - return; - locAnchorPoint.x = point.x; - locAnchorPoint.y = point.y; - } else { - if ((point === locAnchorPoint.x) && (y === locAnchorPoint.y)) - return; - locAnchorPoint.x = point; - locAnchorPoint.y = y; - } - var sizeProvider = this._sizeProvider; - if (sizeProvider instanceof _ccsg.Node) { - sizeProvider.setAnchorPoint(locAnchorPoint); - } - this.emit(ANCHOR_CHANGED); - }, - - /** - * !#en - * Returns a copy of the anchor point in absolute pixels.
- * you can only read it. If you wish to modify it, use setAnchorPoint. - * !#zh - * 返回锚点的绝对像素位置。
- * 你只能读它。如果您要修改它,使用 setAnchorPoint。 - * @see cc.Node#getAnchorPoint - * @method getAnchorPointInPoints - * @return {Vec2} The anchor point in absolute pixels. - * @example - * cc.log("AnchorPointInPoints: " + node.getAnchorPointInPoints()); - */ - getAnchorPointInPoints: function () { - return this._sgNode.getAnchorPointInPoints(); - }, - /** * !#en * Returns a copy the untransformed size of the node.