Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cocos/particle-2d/particle-simulator-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
class Particle {
public pos = new Vec2(0, 0);
public startPos = new Vec2(0, 0);
public color = new Color(0, 0, 0, 255);
public color = { r: 0, g: 0, b: 0, a: 255 };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为 Color 类型对象使用 Uint8ClampedArray 类型数组存储 rgba 数值,此类型数组的元素值添加时会对数值进行四舍五入。
而在 particle-simulator-2d.ts 中计算每帧粒子的颜色数据需要 rgba 值与 dt 浮点值相乘,最终得到的 rgba 浮点值赋值给 color 的 rgba 值时会被四舍五入,导致最终显示结果不符合预期。

Because Color type objects use an array of type Uint8ClampedArray to store rgba values, element values of this array type are rounded when added.
However, calculating the color data of each frame particle in particle-simulator-2d.ts requires multiplying the rgba value by the dt floating point value. The resulting rgba floating point value assigned to the rgba value of color will be rounded, resulting in the final display result not meeting expectations.

public deltaColor = { r: 0, g: 0, b: 0, a: 255 };
public size = 0;
public deltaSize = 0;
Expand Down Expand Up @@ -80,7 +80,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);

Check failure on line 83 in cocos/particle-2d/particle-simulator-2d.ts

View workflow job for this annotation

GitHub Actions / npm_test

Property 'set' does not exist on type '{ r: number; g: number; b: number; a: number; }'.
par.deltaColor.r = par.deltaColor.g = par.deltaColor.b = 0;
par.deltaColor.a = 255;
par.size = 0;
Expand Down
Loading