From d70ced18973915b6adaad045bd54b2bbe3f34902 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 29 Dec 2015 10:49:06 +0800 Subject: [PATCH 01/16] add autoResize property and refactor spacing. --- cocos2d/core/components/CCLayout.js | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 96941cd8d7..76c04e251e 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -109,6 +109,17 @@ var Layout = cc.Class({ } }, + /** + * Whether allow layout to adjust size. + * @property {Boolean} autoResize + * @default true + * @readonly + */ + autoResize: { + default: true, + readonly: true + }, + /** * The margin of layout, it only effect the layout in one direction. * @property {Number} margin @@ -121,10 +132,21 @@ var Layout = cc.Class({ }, /** - * The distance between each element in layout. - * @property {Number} spacing + * The distance in x-axis between each element in layout. + * @property {Number} spacingX */ - spacing: { + spacingX: { + default: 0, + notify: function() { + this._doLayoutDirty(); + } + }, + + /** + * The distance in y-axis between each element in layout. + * @property {Number} spacingY + */ + spacingY: { default: 0, notify: function() { this._doLayoutDirty(); @@ -204,7 +226,7 @@ var Layout = cc.Class({ newWidth += child.width; }); - newWidth += (children.length - 1) * this.spacing + 2 * this.margin; + newWidth += (children.length - 1) * this.spacingX + 2 * this.margin; this.node.setContentSize(newWidth, layoutSize.height); var leftBoundaryOfLayout = -layoutAnchor.x * newWidth; @@ -213,14 +235,14 @@ var Layout = cc.Class({ leftBoundaryOfLayout = (1 - layoutAnchor.x) * newWidth; } - var nextX = leftBoundaryOfLayout + sign * this.margin - sign * this.spacing; + var nextX = leftBoundaryOfLayout + sign * this.margin - sign * this.spacingX; children.forEach(function(child) { var anchorX = child.anchorX; if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) { anchorX = 1 - child.anchorX; } - nextX = nextX + sign * anchorX * child.width + sign * this.spacing; + nextX = nextX + sign * anchorX * child.width + sign * this.spacingX; child.setPosition(cc.p(nextX, child.y)); @@ -236,7 +258,7 @@ var Layout = cc.Class({ newHeight += child.height; }); - newHeight += (children.length - 1) * this.spacing + 2 * this.margin; + newHeight += (children.length - 1) * this.spacingY + 2 * this.margin; this.node.setContentSize(layoutSize.width, newHeight); var bottomBoundaryOfLayout = -layoutAnchor.y * newHeight; @@ -245,14 +267,14 @@ var Layout = cc.Class({ bottomBoundaryOfLayout = (1 - layoutAnchor.y) * newHeight; } - var nextY = bottomBoundaryOfLayout + sign * this.margin - sign * this.spacing; + var nextY = bottomBoundaryOfLayout + sign * this.margin - sign * this.spacingY; children.forEach(function(child) { var anchorY = child.anchorY; if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) { anchorY = 1 - child.anchorY; } - nextY = nextY + sign * anchorY * child.height + sign * this.spacing; + nextY = nextY + sign * anchorY * child.height + sign * this.spacingY; child.setPosition(cc.p(child.x, nextY)); From dd5c4cc72d09c7ab9baef3b80cfcb577ab431e62 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 29 Dec 2015 14:28:41 +0800 Subject: [PATCH 02/16] add basic layout logic --- cocos2d/core/components/CCLayout.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 76c04e251e..e8ddaf5897 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -282,6 +282,20 @@ var Layout = cc.Class({ }.bind(this)); }, + _doLayoutBasic: function(layoutAnchor, layoutSize, children) { + // var allChildrenBoundingBox = null; + + // children.forEach(function(child){ + // if(!allChildrenBoundingBox){ + // allChildrenBoundingBox = child.getBoundingBoxToWorld(); + // } else { + // allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); + // } + // }); + + // this.node.setContentSize(cc.size(allChildrenBoundingBox.width, allChildrenBoundingBox.height)); + }, + _doLayout: function() { var children = this.node.children; var layoutAnchor = this.node.getAnchorPoint(); @@ -291,6 +305,8 @@ var Layout = cc.Class({ this._doLayoutHorizontally(layoutAnchor, layoutSize, children); } else if (this.layoutType === Type.VERTICAL) { this._doLayoutVertically(layoutAnchor, layoutSize, children); + } else if (this.layoutType === Type.BASIC) { + this._doLayoutBasic(layoutAnchor, layoutSize, children); } }, From d22f8e1481d2232b2595b4b398fc1583fcc44695 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Tue, 29 Dec 2015 20:01:30 +0800 Subject: [PATCH 03/16] sync master to 0.7 --- cocos2d/animation/animation-animator.js | 29 ++++++++++++++++++++++++- cocos2d/animation/animation-manager.js | 1 + cocos2d/core/CCGame.js | 4 +++- cocos2d/core/components/CCAnimation.js | 2 +- cocos2d/core/components/CCComponent.js | 8 +++---- test/qunit/unit/test-animation.js | 1 + 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/cocos2d/animation/animation-animator.js b/cocos2d/animation/animation-animator.js index 949bef9044..a23a35caa6 100644 --- a/cocos2d/animation/animation-animator.js +++ b/cocos2d/animation/animation-animator.js @@ -60,13 +60,40 @@ p.resumeState = function (state) { if (state) { state.resume(); } + + if (this.isPaused) { + this.resume(); + } }; p.setStateTime = function (state, time) { if (state) { state.setTime(time); } -} +}; + +p.onStop = function () { + var anims = this.playingAnims; + for (var i = 0, l = anims.length; i < l; i++) { + anims[i].stop(); + } + + Animator.prototype.onStop.call(this); +}; + +p.onPause = function () { + var anims = this.playingAnims; + for (var i = 0, l = anims.length; i < l; i++) { + anims[i].pause(); + } +}; + +p.onResume = function () { + var anims = this.playingAnims; + for (var i = 0, l = anims.length; i < l; i++) { + anims[i].resume(); + } +}; if (CC_DEV) { p.reloadClip = function (state) { diff --git a/cocos2d/animation/animation-manager.js b/cocos2d/animation/animation-manager.js index d798be9a77..0afe8c6910 100644 --- a/cocos2d/animation/animation-manager.js +++ b/cocos2d/animation/animation-manager.js @@ -3,6 +3,7 @@ var JS = cc.js; var AnimationManager = cc.Class({ ctor: function () { this.animators = []; + this.__instanceId = cc.ClassManager.getNewInstanceId(); }, // for manager diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 5271aa0b31..34137f8875 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -224,7 +224,9 @@ var game = /** @lends cc.game# */{ */ cc.winSize = cc.director.getWinSize(); - this._initEvents(); + if (!CC_EDITOR) { + this._initEvents(); + } this._setAnimFrame(); this._runMainLoop(); diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index f5721a8c60..1dabf77190 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -106,7 +106,7 @@ var Animation = cc.Class({ set: function (value, force) { this._currentClip = value; - if (CC_EDITOR && force) { + if (CC_EDITOR && force && value) { this._updateClip(value); } }, diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index bd5a820f22..a690296d72 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -47,8 +47,8 @@ function callOnEnable (self, enable) { self.onEnable(); } } - - cc.director.getScheduler().resumeTarget(this); + + cc.director.getScheduler().resumeTarget(self); _registerEvent(self, true); @@ -66,7 +66,7 @@ function callOnEnable (self, enable) { } } - cc.director.getScheduler().pauseTarget(this); + cc.director.getScheduler().pauseTarget(self); _registerEvent(self, false); @@ -577,7 +577,7 @@ var Component = cc.Class({ isRunning: function () { return this.enabledInHierarchy; }, - + /** *

Schedules a custom selector.
* If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.

diff --git a/test/qunit/unit/test-animation.js b/test/qunit/unit/test-animation.js index 948f85b9a5..aedd9ce7b7 100644 --- a/test/qunit/unit/test-animation.js +++ b/test/qunit/unit/test-animation.js @@ -541,6 +541,7 @@ test('CCAnimation._updateClip', function () { }; animation._updateClip(newClip); + animation.sample(); var clips = animation.getClips(); From 7aa2bf5b4850a5af791634218d15c6fce6519445 Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Tue, 29 Dec 2015 20:40:01 +0800 Subject: [PATCH 04/16] Revert "fix infinite loop in label" This reverts commit b629af483121e9dd8bf5bebd7a2f3642387f5d9e. --- cocos2d/labels/CCSGLabelCanvasRenderCmd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js index 8f2cc0dd1c..a263ec567b 100644 --- a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js @@ -81,6 +81,7 @@ proto._fragmentText = function (strArr, maxWidth, ctx) { //check the first character + var wrappedWords = []; var text = strArr; var allWidth = ctx.measureText(text).width; @@ -89,7 +90,7 @@ var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0; var tmpText = text.substr(fuzzyLen); var width = allWidth - ctx.measureText(tmpText).width; - var sLine = tmpText; + var sLine; var pushNum = 0; //Increased while cycle maximum ceiling. default 100 time @@ -153,7 +154,6 @@ if(text.length > 0) { wrappedWords.push(text); } - return wrappedWords; }; From 56f6c329fdf0d9ea936409e08da9701c95e3b89d Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 29 Dec 2015 20:25:05 +0800 Subject: [PATCH 05/16] finish none layout --- cocos2d/core/components/CCLayout.js | 37 ++++++++++++++++++----------- cocos2d/core/utils/base-node.js | 5 +++- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index e8ddaf5897..dd4dae7716 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -29,9 +29,9 @@ */ var Type = cc.Enum({ /** - *@property {Number} BASIC + *@property {Number} NONE */ - BASIC: 0, + NONE: 0, /** * @property {Number} HORIZONTAL */ @@ -99,10 +99,10 @@ var Layout = cc.Class({ /** * The layout type. * @property {Layout.Type} layoutType - * @default Layout.Type.BASIC + * @default Layout.Type.NONE */ layoutType: { - default: Type.BASIC, + default: Type.NONE, type: Type, notify: function() { this._doLayoutDirty(); @@ -283,17 +283,26 @@ var Layout = cc.Class({ }, _doLayoutBasic: function(layoutAnchor, layoutSize, children) { - // var allChildrenBoundingBox = null; + var allChildrenBoundingBox = null; - // children.forEach(function(child){ - // if(!allChildrenBoundingBox){ - // allChildrenBoundingBox = child.getBoundingBoxToWorld(); - // } else { - // allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); - // } - // }); + children.forEach(function(child){ + if(!allChildrenBoundingBox){ + allChildrenBoundingBox = child.getBoundingBoxToWorld(); + } else { + allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); + } + }); + var leftBottomInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x, allChildrenBoundingBox.y)); + var rightTopInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x + allChildrenBoundingBox.width, + allChildrenBoundingBox.y + allChildrenBoundingBox.height)); + var newSize = cc.size(rightTopInParentSpace.x - leftBottomInParentSpace.x, + rightTopInParentSpace.y - leftBottomInParentSpace.y); + var layoutPosition = this.node.getPosition(); + var newAnchor = cc.p((layoutPosition.x - leftBottomInParentSpace.x) / newSize.width, + (layoutPosition.y - leftBottomInParentSpace.y) / newSize.height); - // this.node.setContentSize(cc.size(allChildrenBoundingBox.width, allChildrenBoundingBox.height)); + this.node.setAnchorPoint(newAnchor); + this.node.setContentSize(newSize); }, _doLayout: function() { @@ -305,7 +314,7 @@ var Layout = cc.Class({ this._doLayoutHorizontally(layoutAnchor, layoutSize, children); } else if (this.layoutType === Type.VERTICAL) { this._doLayoutVertically(layoutAnchor, layoutSize, children); - } else if (this.layoutType === Type.BASIC) { + } else if (this.layoutType === Type.NONE) { this._doLayoutBasic(layoutAnchor, layoutSize, children); } }, diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 78a5a5d5a1..16447dc385 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -887,7 +887,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @return {Rect} The calculated bounding box of the node */ getBoundingBox: function () { - return this._sgNode.getBoundingBox(); + var boundingBox = this._sgNode.getBoundingBox(); + boundingBox.width = this._contentSize.width; + boundingBox.height = this._contentSize.height; + return boundingBox; }, /** From c4b48a4c897ff7b879d496690d1ba01f08dd1b21 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 29 Dec 2015 21:21:21 +0800 Subject: [PATCH 06/16] fix layout child anchor change issue. 1. fix base-node getBoundingBox issue --- cocos2d/core/components/CCLayout.js | 1 + cocos2d/core/utils/base-node.js | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index dd4dae7716..b32fe35b3d 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -205,6 +205,7 @@ var Layout = cc.Class({ children.forEach(function(child) { child.on('size-changed', this._doLayoutDirty, this); child.on('position-changed', this._doLayoutDirty, this); + child.on('anchor-changed', this._doLayoutDirty, this); }.bind(this)); }, diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 16447dc385..3d0ab9ef4d 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -887,10 +887,8 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @return {Rect} The calculated bounding box of the node */ getBoundingBox: function () { - var boundingBox = this._sgNode.getBoundingBox(); - boundingBox.width = this._contentSize.width; - boundingBox.height = this._contentSize.height; - return boundingBox; + var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height); + return cc._rectApplyAffineTransformIn(rect, this.getNodeToParentTransform()); }, /** From abe82c25498289129616adb9ca918aed0b01ad0b Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 29 Dec 2015 23:55:09 +0800 Subject: [PATCH 07/16] Fix text wrap issue for system Label --- cocos2d/labels/CCSGLabelCanvasRenderCmd.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js index 8f2cc0dd1c..4453ce2a70 100644 --- a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js @@ -131,6 +131,7 @@ if (label_symbolRex.test(sLine || tmpText)) { result = label_lastWordRex.exec(sText); fuzzyLen -= result ? result[0].length : 0; + if (fuzzyLen === 0) fuzzyLen = 1; sLine = text.substr(fuzzyLen); sText = text.substr(0, fuzzyLen); From e623270d3b5f7fe5a5f9f7cc2fcdd848dede353d Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 30 Dec 2015 01:46:29 +0800 Subject: [PATCH 08/16] refactoring sprite --- cocos2d/core/components/CCSprite.js | 49 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index b0b44ad0eb..78f7f61c8e 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -72,7 +72,7 @@ var Sprite = cc.Class({ var lastSprite = this._spriteFrame; this._spriteFrame = value; if (this._sgNode) { - this._applySprite(this._sgNode, lastSprite); + this._applySpriteFrame(this._sgNode, lastSprite); // color cleared after reset texture, should reapply color this._sgNode.setColor(this.node._color); this._sgNode.setOpacity(this.node._opacity); @@ -326,7 +326,7 @@ var Sprite = cc.Class({ _applySpriteSize: function (sgNode) { sgNode = sgNode || this._sgNode; - if (this._useOriginalSize) { + if (this._useOriginalSize && this._spriteFrame) { var rect = this._spriteFrame.getRect(); this.node.setContentSize(cc.size(rect.width, rect.height)); } @@ -335,30 +335,28 @@ var Sprite = cc.Class({ } }, - _applySprite: function (sgNode, oldSprite) { - if (oldSprite && oldSprite.off) { - oldSprite.off('load', this._applyCapInset, this); + _onSpriteFrameLoaded: function (event, sgNode) { + var self = this; + sgNode = sgNode || this._sgNode; + sgNode.setSpriteFrame(self._spriteFrame); + self._applyCapInset(sgNode); + self._applySpriteSize(); + if ( !sgNode.isVisible() ) { + sgNode.setVisible(true); + } + }, + + _applySpriteFrame: function (sgNode, oldFrame) { + if (oldFrame && oldFrame.off) { + oldFrame.off('load', this._onSpriteFrameLoaded, this); } if (this._spriteFrame) { - if (!sgNode.isVisible()) { - sgNode.setVisible(true); - } - - sgNode.setSpriteFrame(this._spriteFrame); - var locLoaded = this._spriteFrame.textureLoaded(); - if (!locLoaded) { - if (!this._useOriginalSize) { - sgNode.setContentSize(this.node.getContentSize(true)); - } - this._spriteFrame.once('load', function () { - this._applyCapInset(); - this._applySpriteSize(); - }, this); + if (this._spriteFrame.textureLoaded()) { + this._onSpriteFrameLoaded(null, sgNode); } else { - this._applyCapInset(sgNode); - this._applySpriteSize(sgNode); + this._spriteFrame.once('load', this._onSpriteFrameLoaded, this); } } else { @@ -373,8 +371,15 @@ var Sprite = cc.Class({ _createSgNode: function () { var sgNode = new cc.Scale9Sprite(); + + // should keep the size of the sg node the same as entity, + // otherwise setContentSize may not take effect + sgNode.setContentSize(this.node.getContentSize(true)); + + this._applySpriteSize(sgNode); sgNode.setRenderingType(this._type); - this._applySprite(sgNode, null); + this._applySpriteFrame(sgNode, null); + return sgNode; }, From 28c79dd17de1d772c2c2d2d5a91a9ae306437f23 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 30 Dec 2015 09:43:40 +0800 Subject: [PATCH 09/16] only doLayout when count of children > 0 --- cocos2d/core/components/CCLayout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index b32fe35b3d..d0bff3e5da 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -321,7 +321,7 @@ var Layout = cc.Class({ }, lateUpdate: function() { - if (this._layoutDirty) { + if (this._layoutDirty && this.node.children.length > 0) { this._doLayout(); this._layoutDirty = false; } From 32464f4f660e16e638055a238f97c222afd2730e Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 30 Dec 2015 09:53:59 +0800 Subject: [PATCH 10/16] add defensive programming --- cocos2d/core/components/CCLayout.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index d0bff3e5da..e5f7c553cd 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -293,17 +293,22 @@ var Layout = cc.Class({ allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); } }); - var leftBottomInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x, allChildrenBoundingBox.y)); - var rightTopInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x + allChildrenBoundingBox.width, - allChildrenBoundingBox.y + allChildrenBoundingBox.height)); - var newSize = cc.size(rightTopInParentSpace.x - leftBottomInParentSpace.x, - rightTopInParentSpace.y - leftBottomInParentSpace.y); - var layoutPosition = this.node.getPosition(); - var newAnchor = cc.p((layoutPosition.x - leftBottomInParentSpace.x) / newSize.width, - (layoutPosition.y - leftBottomInParentSpace.y) / newSize.height); - this.node.setAnchorPoint(newAnchor); - this.node.setContentSize(newSize); + if(allChildrenBoundingBox) { + var leftBottomInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x, allChildrenBoundingBox.y)); + var rightTopInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x + allChildrenBoundingBox.width, + allChildrenBoundingBox.y + allChildrenBoundingBox.height)); + + var newSize = cc.size(rightTopInParentSpace.x - leftBottomInParentSpace.x, + rightTopInParentSpace.y - leftBottomInParentSpace.y); + + var layoutPosition = this.node.getPosition(); + var newAnchor = cc.p((layoutPosition.x - leftBottomInParentSpace.x) / newSize.width, + (layoutPosition.y - leftBottomInParentSpace.y) / newSize.height); + + this.node.setAnchorPoint(newAnchor); + this.node.setContentSize(newSize); + } }, _doLayout: function() { From de429aa237b6ca3ece1d67b993983fd195dd3637 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 30 Dec 2015 10:06:09 +0800 Subject: [PATCH 11/16] CCSprite js update --- cocos2d/core/components/CCSprite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 78f7f61c8e..8bf4d450d4 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -315,7 +315,7 @@ var Sprite = cc.Class({ }, _applyCapInset: function (sgNode) { - if (this._type === SpriteType.SLICED) { + if (this._type === SpriteType.SLICED && this._spriteFrame) { sgNode = sgNode || this._sgNode; sgNode.setInsetTop(this._spriteFrame.insetTop); sgNode.setInsetBottom(this._spriteFrame.insetBottom); From c213e720ab1e396fbc4d347d5a8a007761ef505f Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Wed, 30 Dec 2015 10:35:48 +0800 Subject: [PATCH 12/16] update i18n for layout tooltip. --- cocos2d/core/components/CCLayout.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index e5f7c553cd..c9747ef0d2 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -106,7 +106,8 @@ var Layout = cc.Class({ type: Type, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.layout_type' }, /** @@ -117,7 +118,8 @@ var Layout = cc.Class({ */ autoResize: { default: true, - readonly: true + readonly: true, + tooltip: 'i18n:COMPONENT.layout.auto_resize' }, /** @@ -128,7 +130,8 @@ var Layout = cc.Class({ default: 0, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.margin' }, /** @@ -139,7 +142,8 @@ var Layout = cc.Class({ default: 0, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.space_x' }, /** @@ -150,7 +154,8 @@ var Layout = cc.Class({ default: 0, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.space_y' }, /** @@ -163,7 +168,8 @@ var Layout = cc.Class({ type: VerticalDirection, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.vertical_direction' }, /** @@ -176,7 +182,8 @@ var Layout = cc.Class({ type: HorizontalDirection, notify: function() { this._doLayoutDirty(); - } + }, + tooltip: 'i18n:COMPONENT.layout.horizontal_direction' }, }, From 7b95f889ed7bf81b01fd4936bb2e266b94217604 Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Wed, 30 Dec 2015 10:41:38 +0800 Subject: [PATCH 13/16] Revert "Revert "fix infinite loop in label"" This reverts commit 7aa2bf5b4850a5af791634218d15c6fce6519445. --- cocos2d/labels/CCSGLabelCanvasRenderCmd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js index 72fa6f5db4..4453ce2a70 100644 --- a/cocos2d/labels/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/labels/CCSGLabelCanvasRenderCmd.js @@ -81,7 +81,6 @@ proto._fragmentText = function (strArr, maxWidth, ctx) { //check the first character - var wrappedWords = []; var text = strArr; var allWidth = ctx.measureText(text).width; @@ -90,7 +89,7 @@ var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0; var tmpText = text.substr(fuzzyLen); var width = allWidth - ctx.measureText(tmpText).width; - var sLine; + var sLine = tmpText; var pushNum = 0; //Increased while cycle maximum ceiling. default 100 time @@ -155,6 +154,7 @@ if(text.length > 0) { wrappedWords.push(text); } + return wrappedWords; }; From b9cae113105a63c560b70336082037bf97407335 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 30 Dec 2015 14:08:22 +0800 Subject: [PATCH 14/16] sprite should not response the resized event if emit by itself --- cocos2d/core/components/CCSprite.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 8bf4d450d4..95b2e440de 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -384,7 +384,15 @@ var Sprite = cc.Class({ }, _resized: function () { - this.useOriginalSize = false; + if (this._useOriginalSize && this._spriteFrame) { + var rect = this._spriteFrame.getRect(); + var expectedW = rect.width; + var expectedH = rect.height; + var actualSize = this.node.getContentSize(); + if (expectedW !== actualSize.width || expectedH !== actualSize.height) { + this.useOriginalSize = false; + } + } }, }); From ccf69e1815448d5d633576636f50c00f1c5e37ca Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 30 Dec 2015 17:35:35 +0800 Subject: [PATCH 15/16] Everything is convertible to string could be set as the content of label --- cocos2d/labels/CCSGLabel.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos2d/labels/CCSGLabel.js b/cocos2d/labels/CCSGLabel.js index 5263388e85..c9a7a91022 100644 --- a/cocos2d/labels/CCSGLabel.js +++ b/cocos2d/labels/CCSGLabel.js @@ -217,6 +217,14 @@ _ccsg.Label = _ccsg.Node.extend({ }, setString: function(string) { + //convert param to string + if (typeof string === 'string') { + } else if (string.toString) { + string = string.toString(); + } else { + cc.error("could not set param as a string to Label!"); + } + if (this._string === string) return; this._string = string; this._notifyLabelSkinDirty(); From 8807d8d61896d345b300d99bf6655cd6a97e4013 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 30 Dec 2015 17:52:36 +0800 Subject: [PATCH 16/16] ... --- cocos2d/labels/CCSGLabel.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cocos2d/labels/CCSGLabel.js b/cocos2d/labels/CCSGLabel.js index c9a7a91022..4c0dca2acc 100644 --- a/cocos2d/labels/CCSGLabel.js +++ b/cocos2d/labels/CCSGLabel.js @@ -218,11 +218,8 @@ _ccsg.Label = _ccsg.Node.extend({ setString: function(string) { //convert param to string - if (typeof string === 'string') { - } else if (string.toString) { - string = string.toString(); - } else { - cc.error("could not set param as a string to Label!"); + if (typeof string !== 'string') { + string = '' + string; } if (this._string === string) return;