Skip to content

Commit

Permalink
do not update when the opacity of label changed and limit max size of…
Browse files Browse the repository at this point in the history
… ttf. (#4047)

* do not update when the opacity of label change and limit max size of ttf.

* clear opacity flag

* cache opacity flag

* modify the render flag setting when the opacity changes
  • Loading branch information
caryliu1999 authored and pandamicro committed Mar 26, 2019
1 parent 3a1e289 commit 8262ae2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cocos2d/core/CCNode.js
Expand Up @@ -946,7 +946,7 @@ var Node = cc.Class({
set (value) {
if (this._opacity !== value) {
this._opacity = value;
this._renderFlag |= RenderFlow.FLAG_OPACITY | RenderFlow.FLAG_COLOR;
this._renderFlag |= RenderFlow.FLAG_OPACITY;
}
},
range: [0, 255]
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/components/CCLabel.js
Expand Up @@ -31,6 +31,7 @@ const RenderFlow = require('../renderer/render-flow');
const SpriteMaterial = renderEngine.SpriteMaterial;
const dynamicAtlasManager = require('../renderer/utils/dynamic-atlas/manager');
const LabelFrame = require('../renderer/utils/label/label-frame');
const opacityFlag = RenderFlow.FLAG_COLOR | RenderFlow.FLAG_OPACITY;
/**
* !#en Enum for text alignment.
* !#zh 文本横向对齐类型
Expand Down Expand Up @@ -646,8 +647,7 @@ let Label = cc.Class({
let font = this.font;
if (font instanceof cc.BitmapFont) {
this._super();
}
else {
} else {
this._updateRenderData();
this.node._renderFlag &= ~RenderFlow.FLAG_COLOR;
}
Expand Down
4 changes: 4 additions & 0 deletions cocos2d/core/renderer/utils/label/ttf.js
Expand Up @@ -33,6 +33,7 @@ const Overflow = Label.Overflow;

const WHITE = cc.Color.WHITE;
const OUTLINE_SUPPORTED = cc.js.isChildClassOf(LabelOutline, Component);
const MAX_SIZE = 2048;

let _context = null;
let _canvas = null;
Expand Down Expand Up @@ -300,6 +301,9 @@ module.exports = {
//0.0174532925 = 3.141592653 / 180
_canvasSize.width += _drawFontsize * Math.tan(12 * 0.0174532925);
}

_canvasSize.width = Math.min(_canvasSize.width, MAX_SIZE);
_canvasSize.height = Math.min(_canvasSize.height, MAX_SIZE);
}

if (_canvas.width !== _canvasSize.width || CC_QQPLAY) {
Expand Down

0 comments on commit 8262ae2

Please sign in to comment.