From f0b6448e79c557c11cd86ca60a91d375b5f683c1 Mon Sep 17 00:00:00 2001 From: Radu Angelescu Date: Thu, 5 Feb 2026 13:12:31 +0200 Subject: [PATCH] fixed color interpolation for 2d particle systems --- cocos/particle-2d/particle-simulator-2d.ts | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/cocos/particle-2d/particle-simulator-2d.ts b/cocos/particle-2d/particle-simulator-2d.ts index fe623c4e567..b6a809e6b10 100644 --- a/cocos/particle-2d/particle-simulator-2d.ts +++ b/cocos/particle-2d/particle-simulator-2d.ts @@ -47,12 +47,32 @@ function getWorldRotation (node): number { } return rotation; } +class ColorNumber { + public r = 0; + public g = 0; + public b = 0; + public a = 0; + + constructor (r: number, g: number, b: number, a: number) { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + set (r: number, g: number, b: number, a: number): void { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } +} class Particle { public pos = new Vec2(0, 0); public startPos = new Vec2(0, 0); - public color = new Color(0, 0, 0, 255); - public deltaColor = { r: 0, g: 0, b: 0, a: 255 }; + public color = new ColorNumber(0, 0, 0, 255); + public deltaColor = new ColorNumber(0, 0, 0, 255); public size = 0; public deltaSize = 0; public rotation = 0; @@ -81,8 +101,7 @@ const pool = new ParticlePool((par: Particle): void => { par.pos.set(Vec2.ZERO); par.startPos.set(Vec2.ZERO); par.color.set(0, 0, 0, 255); - par.deltaColor.r = par.deltaColor.g = par.deltaColor.b = 0; - par.deltaColor.a = 255; + par.deltaColor.set(0, 0, 0, 255); par.size = 0; par.deltaSize = 0; par.rotation = 0;