From e74bc01add93b679e76c01b05b1f4f97f7feb18d Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 14 Mar 2016 17:52:26 +0800 Subject: [PATCH 1/7] refactoring label, fix blink issue make it works remove unused code --- .../base-nodes/CCSGNodeCanvasRenderCmd.js | 19 ++-- cocos2d/core/label/CCSGLabel.js | 12 +-- .../core/label/CCSGLabelCanvasRenderCmd.js | 93 ++++++++++++------- cocos2d/core/label/CCSGLabelWebGLRenderCmd.js | 2 - 4 files changed, 76 insertions(+), 50 deletions(-) diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js index b0fc26c2b8..eb3a6de44d 100644 --- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js +++ b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js @@ -36,15 +36,16 @@ cc.CustomRenderCmd = function (target, func) { }; _ccsg.Node._dirtyFlags = { - transformDirty: 1 << 0, - visibleDirty: 1 << 1, - colorDirty: 1 << 2, - opacityDirty: 1 << 3, - cacheDirty: 1 << 4, - orderDirty: 1 << 5, - textDirty: 1 << 6, - gradientDirty:1 << 7, - COUNT: 8 + transformDirty: 1 << 0, + visibleDirty: 1 << 1, + colorDirty: 1 << 2, + opacityDirty: 1 << 3, + cacheDirty: 1 << 4, + orderDirty: 1 << 5, + textDirty: 1 << 6, + gradientDirty: 1 << 7, + labelDirty: 1 << 8, + COUNT: 9 }; cc.js.get(_ccsg.Node._dirtyFlags, 'all', function () { var count = _ccsg.Node._dirtyFlags.COUNT; diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 98966095a4..24d8871711 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -115,7 +115,6 @@ _ccsg.Label = _ccsg.Node.extend({ _blendFunc: null, _isUseSystemFont: true, - _labelSkinDirty: true, _labelType: 0, //0 is ttf, 1 is bmfont. _fontHandle: "", //a ttf font name or a bmfont file path. _lineSpacing: 0, @@ -436,16 +435,16 @@ _ccsg.Label = _ccsg.Node.extend({ _notifyLabelSkinDirty: function() { if (CC_EDITOR) { this._updateLabel(); - this._labelSkinDirty = false; } else { - this._labelSkinDirty = true; + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); } }, _createRenderCmd: function() { - if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) + if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { return new _ccsg.Label.WebGLRenderCmd(this); - else + } else { return new _ccsg.Label.CanvasRenderCmd(this); + } }, getContentSize: function() { @@ -916,9 +915,6 @@ cc.BMFontHelper = { this._computeHorizontalKerningForText(this._string); updateFinished = this._alignText(); } - if (updateFinished) { - this._labelSkinDirty = false; - } }, diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index ddffe659d1..b6d617b5c9 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -31,6 +31,62 @@ var proto = _ccsg.Label.TTFLabelBaker.prototype = Object.create(Object.prototype); + + proto.updateStatus = function () { + var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag; + var colorDirty = locFlag & flags.colorDirty, + opacityDirty = locFlag & flags.opacityDirty; + + if (colorDirty) + this._updateDisplayColor(); + if (opacityDirty) + this._updateDisplayOpacity(); + + if(colorDirty || opacityDirty){ + this._updateColor(); + }else if(locFlag & flags.labelDirty) { + this._rebuildLabelSkin(); + } + + if (this._dirtyFlag & flags.transformDirty){ + this.transform(this.getParentRenderCmd(), true); + this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty ^ this._dirtyFlag; + } + }; + + proto._syncStatus = function (parentCmd) { + var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag; + var parentNode = parentCmd ? parentCmd._node : null; + + if(parentNode && parentNode._cascadeColorEnabled && (parentCmd._dirtyFlag & flags.colorDirty)) + locFlag |= flags.colorDirty; + + if(parentNode && parentNode._cascadeOpacityEnabled && (parentCmd._dirtyFlag & flags.opacityDirty)) + locFlag |= flags.opacityDirty; + + if(parentCmd && (parentCmd._dirtyFlag & flags.transformDirty)) + locFlag |= flags.transformDirty; + + var colorDirty = locFlag & flags.colorDirty, + opacityDirty = locFlag & flags.opacityDirty; + + this._dirtyFlag = locFlag; + + if (colorDirty) + this._syncDisplayColor(); + if (opacityDirty) + this._syncDisplayOpacity(); + + if(colorDirty || opacityDirty){ + this._updateColor(); + } else if(locFlag & flags.labelDirty) { + this._rebuildLabelSkin(); + } + + if (locFlag & flags.transformDirty) //update the transform + this.transform(parentCmd); + }; + proto._getLineHeight = function () { var nodeSpacingY = this._node.getLineHeight(); if (nodeSpacingY === 0) { @@ -162,26 +218,11 @@ return wrappedWords; }; - proto._updateDisplayOpacity = function (parentOpacity) { - _ccsg.Node.RenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity); - var node = this._node; - if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - //specify opacity to quad - var color = cc.color(255, 255, 255, this._displayedOpacity); - var quad = this._quad; - quad._bl.colors = color; - quad._br.colors = color; - quad._tl.colors = color; - quad._tr.colors = color; - this._quadDirty = true; - } - }; - proto._updateDisplayColor = function (parentColor) { _ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor); var node = this._node; if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - node._labelSkinDirty = true; + this._rebuildLabelSkin(); } }; @@ -189,7 +230,7 @@ _ccsg.Node.RenderCmd.prototype._syncDisplayColor.call(this, parentColor); var node = this._node; if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - node._labelSkinDirty = true; + this._rebuildLabelSkin(); } }; @@ -397,18 +438,11 @@ }; proto._rebuildLabelSkin = function () { + this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.labelDirty ^ this._dirtyFlag; var node = this._node; - if (node._labelSkinDirty) { - if (node._labelType === _ccsg.Label.Type.TTF || - node._labelType === _ccsg.Label.Type.SystemFont) { - this._bakeLabel(); - this._prepareQuad(); - } - else { - node._updateContent(); - } - this._node._labelSkinDirty = false; - } + this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node); + + node._updateLabel(); }; })(); @@ -435,10 +469,7 @@ proto.constructor = _ccsg.Label.CanvasRenderCmd; proto.rendering = function (ctx, scaleX, scaleY) { - this._rebuildLabelSkin(); - var node = this._node; - this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node); if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js index 55ddb784b7..1541f8f9ce 100644 --- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js @@ -59,9 +59,7 @@ proto.rendering = function (ctx) { var node = this._node; - this._rebuildLabelSkin(); - this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node); if(node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont){ From c016ae2aec51035966c836851d82504c10f0f842 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 14:33:40 +0800 Subject: [PATCH 2/7] fix bmfont getContentSize cause chilrenOrderDrity --- cocos2d/core/label/CCSGLabel.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 24d8871711..a417992ea1 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -449,19 +449,19 @@ _ccsg.Label = _ccsg.Node.extend({ getContentSize: function() { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._updateLabel(); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); } return _ccsg.Node.prototype.getContentSize.call(this); }, _getWidth: function () { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._updateLabel(); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); } return _ccsg.Node.prototype._getWidth.call(this); }, _getHeight: function () { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._updateLabel(); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); } return _ccsg.Node.prototype._getHeight.call(this); }, From 9cd4dd5abafd98e4958d14bc44756ca36769a9f4 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 14:44:29 +0800 Subject: [PATCH 3/7] reuse textDirty dirty flag --- cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js | 3 +-- cocos2d/core/label/CCSGLabel.js | 8 ++++---- cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js index 1d6e22e114..b7facce48e 100644 --- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js +++ b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js @@ -44,8 +44,7 @@ _ccsg.Node._dirtyFlags = { orderDirty: 1 << 5, textDirty: 1 << 6, gradientDirty: 1 << 7, - labelDirty: 1 << 8, - COUNT: 9 + COUNT: 8 }; cc.js.get(_ccsg.Node._dirtyFlags, 'all', function () { var count = _ccsg.Node._dirtyFlags.COUNT; diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index a417992ea1..b5cfcf8d60 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -436,7 +436,7 @@ _ccsg.Label = _ccsg.Node.extend({ if (CC_EDITOR) { this._updateLabel(); } else { - this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty); } }, _createRenderCmd: function() { @@ -449,19 +449,19 @@ _ccsg.Label = _ccsg.Node.extend({ getContentSize: function() { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty); } return _ccsg.Node.prototype.getContentSize.call(this); }, _getWidth: function () { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty); } return _ccsg.Node.prototype._getWidth.call(this); }, _getHeight: function () { if (!CC_EDITOR && !cc.sizeEqualToSize(this._contentSize, this._renderCmd._realRenderingSize)) { - this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.labelDirty); + this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty); } return _ccsg.Node.prototype._getHeight.call(this); }, diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index b6d617b5c9..ff2364862e 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -44,7 +44,7 @@ if(colorDirty || opacityDirty){ this._updateColor(); - }else if(locFlag & flags.labelDirty) { + }else if(locFlag & flags.textDirty) { this._rebuildLabelSkin(); } @@ -79,7 +79,7 @@ if(colorDirty || opacityDirty){ this._updateColor(); - } else if(locFlag & flags.labelDirty) { + } else if(locFlag & flags.textDirty) { this._rebuildLabelSkin(); } @@ -438,7 +438,7 @@ }; proto._rebuildLabelSkin = function () { - this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.labelDirty ^ this._dirtyFlag; + this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.textDirty ^ this._dirtyFlag; var node = this._node; this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node); From 34b62651d19d809e83224baa9c18ad59b1f5fb22 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 15:36:04 +0800 Subject: [PATCH 4/7] refactoring label --- cocos2d/core/label/CCSGLabel.js | 4 +- .../core/label/CCSGLabelCanvasRenderCmd.js | 80 +++++++++++-------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index b5cfcf8d60..0367f9df57 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -790,10 +790,10 @@ cc.BMFontHelper = { var contentSize = cc.size(this._labelWidth, this._labelHeight); if (this._labelWidth <= 0) { - contentSize.width = longestLine; + contentSize.width = parseFloat(longestLine.toFixed(2)); } if (this._labelHeight <= 0) { - contentSize.height = this._textDesiredHeight; + contentSize.height = parseFloat(this._textDesiredHeight.toFixed(2)); } _ccsg.Node.prototype.setContentSize.call(this, contentSize); diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index ff2364862e..44ccd44a3f 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -222,7 +222,8 @@ _ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor); var node = this._node; if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - this._rebuildLabelSkin(); + this._updateTexture(); + this._prepareQuad(); } }; @@ -230,11 +231,12 @@ _ccsg.Node.RenderCmd.prototype._syncDisplayColor.call(this, parentColor); var node = this._node; if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - this._rebuildLabelSkin(); + this._updateTexture(); + this._prepareQuad(); } }; - proto._calculateLabelFont = function(canvasSize) { + proto._calculateLabelFont = function() { var node = this._node; var paragraphedStrings = node._string.split('\n'); @@ -253,9 +255,9 @@ if (node._isWrapText) { var totalLength = 0; for (i = 0; i < paragraphedStrings.length; ++i) { - totalLength += ((paragraphLength[i] / canvasSize.width + 1) | 0) * canvasSize.width; + totalLength += ((paragraphLength[i] / this._canvasSize.width + 1) | 0) * this._canvasSize.width; } - var scale = canvasSize.width * ((canvasSize.height / this._getLineHeight()) | 0) / totalLength; + var scale = this._canvasSize.width * ((this._canvasSize.height / this._getLineHeight()) | 0) / totalLength; this._drawFontsize = (this._drawFontsize * Math.min(Math.sqrt(scale), 1)) | 0; fontDesc = this._drawFontsize.toString() + 'px ' + fontFamily; this._labelContext.font = fontDesc; @@ -267,8 +269,8 @@ for (i = 0; i < paragraphedStrings.length; ++i) { if (maxLength < paragraphLength[i]) maxLength = paragraphLength[i]; } - var scaleX = canvasSize.width / maxLength; - var scaleY = canvasSize.height / totalHeight; + var scaleX = this._canvasSize.width / maxLength; + var scaleY = this._canvasSize.height / totalHeight; this._drawFontsize = (this._drawFontsize * Math.min(1, scaleX, scaleY)) | 0; fontDesc = this._drawFontsize.toString() + 'px ' + fontFamily; @@ -299,7 +301,7 @@ return cc.size(canvasWidth, canvasHeight); }; - proto._calculateSplitedStrings = function(canvasSize) { + proto._calculateSplitedStrings = function() { var node = this._node; var ctx = this._labelContext; @@ -309,7 +311,7 @@ if (node._isWrapText) { this._splitedStrings = []; for (i = 0; i < paragraphedStrings.length; ++i) { - this._splitedStrings = this._splitedStrings.concat(this._fragmentText(paragraphedStrings[i], canvasSize.width, ctx)); + this._splitedStrings = this._splitedStrings.concat(this._fragmentText(paragraphedStrings[i], this._canvasSize.width, ctx)); } } else { @@ -318,14 +320,15 @@ }; - proto._updateLabelDimensions = function(canvasSize, ctx) { + proto._updateLabelDimensions = function() { var node = this._node; var paragraphedStrings = node._string.split('\n'); var i; + var ctx = this._labelContext; if (_ccsg.Label.Overflow.RESIZE_HEIGHT === node._overFlow) { - canvasSize.height = this._splitedStrings.length * this._getLineHeight(); - _ccsg.Node.prototype.setContentSize.call(node, canvasSize); + this._canvasSize.height = this._splitedStrings.length * this._getLineHeight(); + _ccsg.Node.prototype.setContentSize.call(node, this._canvasSize); } else if(_ccsg.Label.Overflow.NONE === node._overFlow) { this._splitedStrings = paragraphedStrings; @@ -337,18 +340,17 @@ } canvasSizeY = this._splitedStrings.length * this._getLineHeight(); - canvasSize.width = canvasSizeX; - canvasSize.height = canvasSizeY; - _ccsg.Node.prototype.setContentSize.call(node, canvasSize); + this._canvasSize.width = parseFloat(canvasSizeX.toFixed(2)); + this._canvasSize.height = parseFloat(canvasSizeY.toFixed(2)); + _ccsg.Node.prototype.setContentSize.call(node, this._canvasSize); } - this._labelCanvas.width = canvasSize.width; - this._labelCanvas.height = canvasSize.height; + this._labelCanvas.width = this._canvasSize.width; + this._labelCanvas.height = this._canvasSize.height; - this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height); }; - proto._calculateFillTextStartPosition = function(canvasSize) { + proto._calculateFillTextStartPosition = function() { var node = this._node; var lineHeight = this._getLineHeight(); var lineCount = this._splitedStrings.length; @@ -356,10 +358,10 @@ var firstLinelabelY; if (cc.TextAlignment.RIGHT === node._hAlign) { - labelX = canvasSize.width; + labelX = this._canvasSize.width; } else if (cc.TextAlignment.CENTER === node._hAlign) { - labelX = canvasSize.width / 2; + labelX = this._canvasSize.width / 2; } else { labelX = 0; @@ -369,10 +371,10 @@ firstLinelabelY = 0; } else if (cc.VerticalTextAlignment.CENTER === node._vAlign) { - firstLinelabelY = canvasSize.height / 2 - lineHeight * (lineCount - 1) / 2; + firstLinelabelY = this._canvasSize.height / 2 - lineHeight * (lineCount - 1) / 2; } else { - firstLinelabelY = canvasSize.height - lineHeight * (lineCount - 1); + firstLinelabelY = this._canvasSize.height - lineHeight * (lineCount - 1); } return cc.p(labelX, firstLinelabelY); @@ -410,24 +412,34 @@ var node = this._node; this._drawFontsize = node._fontSize; - var canvasSize = this._calculateCanvasSize(); + this._canvasSize = this._calculateCanvasSize(); //Note: don't change the calling order of the following 3 statements - var fontDesc = this._calculateLabelFont(canvasSize); - this._calculateSplitedStrings(canvasSize); - this._updateLabelDimensions(canvasSize, this._labelContext); - - //this._labelContext.fillStyle = "rgb(128,128,128)"; - //this._labelContext.fillRect(0,0,this._labelCanvas.width,this._labelCanvas.height); - var color = this._displayedColor; - this._labelContext.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')'; + this._fontDesc = this._calculateLabelFont(); + this._calculateSplitedStrings(); + this._updateLabelDimensions(); this._calculateTextBaseline(); - var startPosition = this._calculateFillTextStartPosition(canvasSize); + this._updateTexture(); + + }; + + proto._updateTexture = function() { + this._canvasSize = this._calculateCanvasSize(); + + this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height); + + + this._fontDesc = this._calculateLabelFont(); + this._labelContext.font = this._fontDesc; + + var startPosition = this._calculateFillTextStartPosition(); var lineHeight = this._getLineHeight(); - this._labelContext.font = fontDesc; + var color = this._displayedColor; + this._labelContext.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')'; + //do real rendering for (var i = 0; i < this._splitedStrings.length; ++i) { this._labelContext.fillText(this._splitedStrings[i], startPosition.x, startPosition.y + i * lineHeight); From bb8481e184119229f489b369c092c9e51586e3da Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 16:42:12 +0800 Subject: [PATCH 5/7] fix label color opacity issue --- .../core/label/CCSGLabelCanvasRenderCmd.js | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index 44ccd44a3f..5a8a8b263b 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -218,23 +218,6 @@ return wrappedWords; }; - proto._updateDisplayColor = function (parentColor) { - _ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor); - var node = this._node; - if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - this._updateTexture(); - this._prepareQuad(); - } - }; - - proto._syncDisplayColor = function (parentColor) { - _ccsg.Node.RenderCmd.prototype._syncDisplayColor.call(this, parentColor); - var node = this._node; - if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) { - this._updateTexture(); - this._prepareQuad(); - } - }; proto._calculateLabelFont = function() { var node = this._node; @@ -425,12 +408,13 @@ }; + proto._updateColor = function() { + this._rebuildLabelSkin(); + }; + proto._updateTexture = function() { - this._canvasSize = this._calculateCanvasSize(); - this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height); - this._fontDesc = this._calculateLabelFont(); this._labelContext.font = this._fontDesc; From 963dad915281290e698aeac16ce841a62de91afb Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 17:04:11 +0800 Subject: [PATCH 6/7] we should update editbox size first. --- cocos2d/core/components/CCEditBox.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index c8a82ce559..7f43a21dea 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -276,6 +276,9 @@ var EditBox = cc.Class({ this._createBackgroundSprite(); + if (!this._useOriginalSize) { + sgNode.setContentSize(this.node.getContentSize()); + } sgNode.inputMode = this.inputMode; sgNode.maxLength = this.maxLength; @@ -290,9 +293,6 @@ var EditBox = cc.Class({ sgNode.returnType = this.returnType; sgNode.setLineHeight(this.lineHeight); - if (!this._useOriginalSize) { - sgNode.setContentSize(this.node.getContentSize()); - } sgNode.setDelegate(this); }, From e6336209c9ecb0f280f7574a629a1f0f89abee25 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 16 Mar 2016 18:11:30 +0800 Subject: [PATCH 7/7] don't excluse color,opacity and textDirty logic --- cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index 5a8a8b263b..28a557549b 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -42,9 +42,7 @@ if (opacityDirty) this._updateDisplayOpacity(); - if(colorDirty || opacityDirty){ - this._updateColor(); - }else if(locFlag & flags.textDirty) { + if(colorDirty || opacityDirty || (locFlag & flags.textDirty)){ this._rebuildLabelSkin(); } @@ -77,9 +75,7 @@ if (opacityDirty) this._syncDisplayOpacity(); - if(colorDirty || opacityDirty){ - this._updateColor(); - } else if(locFlag & flags.textDirty) { + if(colorDirty || opacityDirty || (locFlag & flags.textDirty)){ this._rebuildLabelSkin(); } @@ -408,9 +404,9 @@ }; - proto._updateColor = function() { - this._rebuildLabelSkin(); - }; + // proto._updateColor = function() { + // this._rebuildLabelSkin(); + // }; proto._updateTexture = function() { this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height);