mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 11:02:40 +08:00
Fix color channel value overflow issue (#3110)
This commit is contained in:
@@ -263,7 +263,8 @@ var Color = (function () {
|
||||
* color.setR(255); // Color {r: 255, g: 0, b: 0, a: 255}
|
||||
*/
|
||||
proto.setR = function (red) {
|
||||
this._val = ((this._val & 0xffffff00) | ~~red) >>> 0;
|
||||
red = ~~cc.misc.clampf(red, 0, 255);
|
||||
this._val = ((this._val & 0xffffff00) | red) >>> 0;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
@@ -286,7 +287,8 @@ var Color = (function () {
|
||||
* color.setG(255); // Color {r: 0, g: 255, b: 0, a: 255}
|
||||
*/
|
||||
proto.setG = function (green) {
|
||||
this._val = ((this._val & 0xffff00ff) | (~~green << 8)) >>> 0;
|
||||
green = ~~cc.misc.clampf(green, 0, 255);
|
||||
this._val = ((this._val & 0xffff00ff) | (green << 8)) >>> 0;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
@@ -309,7 +311,8 @@ var Color = (function () {
|
||||
* color.setB(255); // Color {r: 0, g: 0, b: 255, a: 255}
|
||||
*/
|
||||
proto.setB = function (blue) {
|
||||
this._val = ((this._val & 0xff00ffff) | (~~blue << 16)) >>> 0;
|
||||
blue = ~~cc.misc.clampf(blue, 0, 255);
|
||||
this._val = ((this._val & 0xff00ffff) | (blue << 16)) >>> 0;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
@@ -332,7 +335,8 @@ var Color = (function () {
|
||||
* color.setA(0); // Color {r: 0, g: 0, b: 0, a: 0}
|
||||
*/
|
||||
proto.setA = function (alpha) {
|
||||
this._val = ((this._val & 0x00ffffff) | ((~~alpha << 24) >>> 0)) >>> 0;
|
||||
alpha = ~~cc.misc.clampf(alpha, 0, 255);
|
||||
this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user