mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
fixed label error (#2664)
* fixed label error * should not render label if string is empty * improve color render flag
This commit is contained in:
@@ -909,7 +909,10 @@ var Node = cc.Class({
|
||||
set (value) {
|
||||
if (this._color.a !== value) {
|
||||
this._color.a = value;
|
||||
this._renderFlag |= RenderFlow.FLAG_COLOR;
|
||||
|
||||
if (this._renderComponent) {
|
||||
this._renderFlag |= RenderFlow.FLAG_COLOR;
|
||||
}
|
||||
}
|
||||
},
|
||||
range: [0, 255]
|
||||
@@ -933,7 +936,10 @@ var Node = cc.Class({
|
||||
if (CC_DEV && value.a !== 255) {
|
||||
cc.warnID(1626);
|
||||
}
|
||||
this._renderFlag |= RenderFlow.FLAG_COLOR;
|
||||
|
||||
if (this._renderComponent) {
|
||||
this._renderFlag |= RenderFlow.FLAG_COLOR;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -28,6 +28,7 @@ const macro = require('../platform/CCMacro');
|
||||
const RenderComponent = require('./CCRenderComponent');
|
||||
const renderer = require('../renderer');
|
||||
const renderEngine = require('../renderer/render-engine');
|
||||
const RenderFlow = require('../renderer/render-flow');
|
||||
const SpriteMaterial = renderEngine.SpriteMaterial;
|
||||
|
||||
/**
|
||||
@@ -161,7 +162,7 @@ let _canvasPool = {
|
||||
}
|
||||
}
|
||||
|
||||
data.width = data.height = 1;
|
||||
data._canvas.width = data._canvas.height = 1;
|
||||
return data;
|
||||
},
|
||||
put (canvas) {
|
||||
@@ -221,6 +222,8 @@ var Label = cc.Class({
|
||||
if (this.string !== oldValue) {
|
||||
this._updateRenderData();
|
||||
}
|
||||
|
||||
this._checkStringEmpty();
|
||||
},
|
||||
multiline: true,
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.label.string'
|
||||
@@ -495,6 +498,7 @@ var Label = cc.Class({
|
||||
this.useSystemFont = true;
|
||||
}
|
||||
|
||||
this._checkStringEmpty();
|
||||
this._updateAssembler();
|
||||
this._activateMaterial();
|
||||
},
|
||||
@@ -503,6 +507,15 @@ var Label = cc.Class({
|
||||
this._resetAssemblerData();
|
||||
},
|
||||
|
||||
_checkStringEmpty () {
|
||||
if (!this.string) {
|
||||
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
|
||||
}
|
||||
else {
|
||||
this.node._renderFlag |= RenderFlow.FLAG_RENDER;
|
||||
}
|
||||
},
|
||||
|
||||
_resetAssemblerData () {
|
||||
if (this._assemblerData) {
|
||||
_canvasPool.put(this._assemblerData);
|
||||
@@ -546,7 +559,6 @@ var Label = cc.Class({
|
||||
|
||||
this._texture = new cc.Texture2D();
|
||||
this._texture.initWithElement(this._assemblerData._canvas);
|
||||
this._texture.handleLoadedTexture();
|
||||
|
||||
material = new SpriteMaterial();
|
||||
material.texture = this._texture;
|
||||
@@ -556,6 +568,7 @@ var Label = cc.Class({
|
||||
this._texture.url = this.uuid + '_texture';
|
||||
}
|
||||
|
||||
material.color = this.node.color;
|
||||
this.setMaterial(material);
|
||||
},
|
||||
|
||||
|
||||
@@ -69,15 +69,15 @@ _proto._worldTransform = function (node) {
|
||||
}
|
||||
|
||||
_proto._color = function (node) {
|
||||
if (node._renderFlag & RENDER || node._renderFlag & CUSTOM_IA_RENDER) {
|
||||
let comp = node._renderComponent;
|
||||
let material = comp._material;
|
||||
if (material) {
|
||||
material.color = node.color;
|
||||
material.updateHash();
|
||||
}
|
||||
let comp = node._renderComponent;
|
||||
let material = comp._material;
|
||||
if (material) {
|
||||
material.color = node.color;
|
||||
material.updateHash();
|
||||
|
||||
// reset flag when set color to material successfully
|
||||
node._renderFlag &= ~COLOR;
|
||||
}
|
||||
node._renderFlag &= ~COLOR;
|
||||
this._next._func(node);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user