Skip to content

Commit

Permalink
Fix the problem that bmfont font opacity is invalid. (#16670)
Browse files Browse the repository at this point in the history
* Fix the problem that bmfont font opacity is invalid.

* Add comment

---------

Co-authored-by: qiuguohua <[email protected]>
  • Loading branch information
qiuguohua and qiuguohua authored Jan 10, 2024
1 parent 16382fa commit ee3bbcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cocos/2d/assembler/label/bmfontUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ export const bmfontUtils = {
// TextProcessing
processing.processingString(true, style, layout, outputLayoutData, comp.string);
// generateVertex
this.resetRenderData(comp);
outputRenderData.quadCount = 0;
processing.generateRenderInfo(true, style, layout, outputLayoutData, outputRenderData,

Check failure on line 121 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected newline after '('

Check failure on line 121 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected newline between arguments/params

Check failure on line 121 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected newline between arguments/params

Check failure on line 121 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected newline between arguments/params

Check failure on line 121 in cocos/2d/assembler/label/bmfontUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected newline between arguments/params
comp.string, this.generateVertexData);

renderData.dataLength = outputRenderData.quadCount;
renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3);
if (renderData.dataLength !== outputRenderData.quadCount) {
this.resetRenderData(comp);
renderData.dataLength = outputRenderData.quadCount;
renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3);
}
const datalist = renderData.data;
for (let i = 0, l = outputRenderData.quadCount; i < l; i++) {
datalist[i] = outputRenderData.vertexBuffer[i];
Expand All @@ -136,7 +137,14 @@ export const bmfontUtils = {
_comp.actualFontSize = style.actualFontSize;
_uiTrans.setContentSize(outputLayoutData.nodeContentSize);
this.updateUVs(comp);// dirty need
this.updateColor(comp); // dirty need
// It is reasonable that the '_comp.node._uiProps.colorDirty' interface should be used.
// But this function is not called when just modifying the opacity.
// So the value of '_comp.node._uiProps.colorDirty' does not change.
// And _uiProps.colorDirty is synchronized with renderEntity.colorDirty.
if (_comp.renderEntity.colorDirty) {
this.updateColor(comp); // dirty need
_comp.node._uiProps.colorDirty = false;
}

renderData.vertDirty = false;
_comp = null;
Expand Down
4 changes: 4 additions & 0 deletions cocos/2d/renderer/render-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export class RenderEntity {

protected _colorDirty = true;
get colorDirty (): boolean {
if (JSB) {
// Synchronize values set from native to JS
this._colorDirty = !!this._boolSharedBuffer[RenderEntityBoolSharedBufferView.colorDirty];
}
return this._colorDirty;
}
set colorDirty (val: boolean) {
Expand Down

0 comments on commit ee3bbcf

Please sign in to comment.