Skip to content

Commit

Permalink
Optimize color refresh logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Canvasfull committed Oct 9, 2023
1 parent b65d5d4 commit 0944eea
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cocos/spine/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ export interface SkeletonDrawData {
indexCount: number;
}

export interface TempColor {
r:number;

Check warning on line 138 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected a space after the ':'
g:number;

Check warning on line 139 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected a space after the ':'
b:number;

Check warning on line 140 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected a space after the ':'
a:number;

Check warning on line 141 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected a space after the ':'
}

/**
* @en
* The Sockets attached to bones, synchronous transform with spine animation.
Expand Down Expand Up @@ -306,7 +313,7 @@ export class Skeleton extends UIRenderer {
_iLength = 0;
_iBuffer: Uint8Array | null = null;
_model: any;
_tempColor: Color = new Color(1, 1, 1, 1);
_tempColor: TempColor = {r: 0, g: 0, b: 0, a: 0};

Check failure on line 316 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

A space is required after '{'

Check failure on line 316 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

A space is required before '}'

constructor () {
super();
Expand Down Expand Up @@ -1605,15 +1612,21 @@ export class Skeleton extends UIRenderer {
* @engineInternal
*/
public _updateColor (): void {
const a = this.node._uiProps.opacity;
if (this._tempColor.r === this._color.r &&

Check failure on line 1616 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'&&' should be placed at the beginning of the line
this._tempColor.g === this.color.g &&

Check failure on line 1617 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'&&' should be placed at the beginning of the line
this._tempColor.b === this.color.b &&

Check failure on line 1618 in cocos/spine/skeleton.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'&&' should be placed at the beginning of the line
this._tempColor.a === a) {
return;
}
this.node._uiProps.colorDirty = true;
this._tempColor.r = this._color.r;
this._tempColor.g = this._color.g;
this._tempColor.b = this._color.b;
this._tempColor.a = a;
const r = this._color.r / 255.0;
const g = this._color.g / 255.0;
const b = this._color.b / 255.0;
const a = this.node._uiProps.opacity;
if (this._tempColor.r === r && this._tempColor.g === g && this._tempColor.b === b) {
return;
}
this._tempColor.set(r, g, b, this._tempColor.a);
this._instance.setColor(r, g, b, a);
}

Expand Down

0 comments on commit 0944eea

Please sign in to comment.