color hex bug fix (#6180)

This commit is contained in:
ChiaNing
2020-02-18 16:03:03 +08:00
committed by GitHub
parent 1c6c605cc6
commit 8c1b380424
2 changed files with 16 additions and 7 deletions
+8 -7
View File
@@ -93,14 +93,15 @@ export class Color extends ValueType {
}
/**
* @zh 根据指定整型数据设置颜色
* @zh 从十六进制颜色字符串中读入颜色到 out 中
*/
public static fromHex <Out extends IColorLike> (out: Out, hex: number) {
out.r = ((hex >> 24)) / 255.0;
out.g = ((hex >> 16) & 0xff) / 255.0;
out.b = ((hex >> 8) & 0xff) / 255.0;
out.a = ((hex) & 0xff) / 255.0;
public static fromHEX <Out extends IColorLike> (out: Out, hexString: string) {
hexString = (hexString.indexOf('#') === 0) ? hexString.substring(1) : hexString;
out.r = parseInt(hexString.substr(0, 2), 16) || 0;
out.g = parseInt(hexString.substr(2, 2), 16) || 0;
out.b = parseInt(hexString.substr(4, 2), 16) || 0;
out.a = parseInt(hexString.substr(6, 2), 16) || 255;
out._val = ((out.a << 24) >>> 0) + (out.b << 16) + (out.g << 8) + out.r;
return out;
}
+8
View File
@@ -357,6 +357,14 @@ replaceProperty(Color, 'Color', [
target: Color,
targetName: 'Color',
},
{
name: 'fromHex',
newName: 'fromHEX',
customFunction: function (...args: any) {
let arg1 = args[1].toString(16);
return cc.Color.fromHEX(args[0], arg1);
},
},
]);
replaceProperty(Mat3, 'Mat3', [