Skip to content
LinearColor

[Basic Type](../groups/Basic Type.Basic Type.md) / LinearColor

LinearColor Class

r, g, b The effective range of color values is 0.0<=value<=1.0

Table of contents

Accessors

a(): number
Get the a value of the current LinearColor
b(): num[b](mw.LinearColor.md#b)er
Get the b-value of the current LinearColor
g(): number
Get the g value of the current LinearColor
r(): numbe[r](mw.LinearColor.md#r)
Get the r value of the current LinearColor
black(): LinearColor
Black (0,0,0,1)
blue(): LinearColor
Blue (0,0,1,1)
gray(): LinearColor
Grey (0.5, 0.5, 0.5, 1)
green(): LinearColor
Green (0,1,0,1)
red(): LinearColor
Red (1,0,0,1)
white(): LinearColor
White (1, 1, 1, 1)
yellow(): LinearColor
Yellow (1, 1, 0, 1)

Methods

addition(linearColorB: LinearColor, outer?: LinearColor): LinearColor other
Addition of color values
clone(): LinearColor other
Clone the current linear color
division(linearColorB: LinearColor, outer?: LinearColor): LinearColor other
Color value division
equality(linearColorB: LinearColor, epsilon?: number): boolean other
Determine if two color values are equal
fromString(jsonStr: string): LinearColor other
Generate a new object with data
inequality(linearColorB: LinearColor, epsilon?: number): boolean other
Multiplying color values
multiply
:-----
subtraction(linearColorB: LinearColor, outer?: LinearColor): LinearColor other
Subtract color values
toString(): string other
Output object properties in string form
colorHexToLinearColor(inColorHex: string, outer?: LinearColor): LinearColor other
Convert HexColor to LinearColor
colorHsvToLinearColor(h: number, s: number, v: number, outer?: LinearColor): LinearColor other
Convert HsvColor to LinearColor
colorToLinearColor(r: number, g: number, b: number, a?: number, outer?: LinearColor): LinearColor other
Convert current color
fromString(jsonStr: string): LinearColor other
Generate a new object with data
makeFromHSV(h: number, s: number, v: number, outer?: LinearColor): LinearColor other
Convert byte tone saturation brightness to LinearColor
random(outer?: LinearColor): LinearColor other
Return a new color with random RGB values and an Alpha of 1.0

Construct a new Color using the given values of r, g, and b

Parameters

r numberr Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number
g numberg Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number
b numberb Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number

new LinearColor(r, g, b, a)

Construct a new Color using the given values of r, g, b, and a

Parameters

r numberr Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number
g numberg Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number
b numberb Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number
a numbera Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number

new LinearColor(v)

Build a new LinearColor using the given Vector object

Parameters

v VectorVector object

new LinearColor(c)

Build a new LinearColor using the given LinearColor

Parameters

c LinearColorVector object

Accessors

a

get a(): number

set a(v): void

Get the a value of the current LinearColor

Returns

number

Set the value of a for the current LinearColor

Parameters

v numbera range: The effective range of brightness is 0.0<=value<=1.0 type: floating-point number

b

get b(): number

set b(v): void

Get the b-value of the current LinearColor

Returns

number

Set the b-value of the current LinearColor

Parameters

v numberb range: The effective range of brightness is 0.0<=value<=1.0 type: floating-point number

g

get g(): number

set g(v): void

Get the g value of the current LinearColor

Returns

number

What is the valid range for setting the g-value of the current LinearColor color value

Parameters

v numberg range: The effective range of color is 0.0<=value<=1.0 type: floating-point number

r

get r(): number

set r(v): void

Get the r value of the current LinearColor

Returns

number

Set the r value of the current LinearColor

Parameters

v numberr range: The effective range of brightness is 0.0<=value<=1.0 type: floating-point number

black

Static get black(): LinearColor

Black (0,0,0,1)

Returns

LinearColor

blue

Static get blue(): LinearColor

Blue (0,0,1,1)

Returns

LinearColor

gray

Static get gray(): LinearColor

Grey (0.5, 0.5, 0.5, 1)

Returns

LinearColor

green

Static get green(): LinearColor

Green (0,1,0,1)

Returns

LinearColor

red

Static get red(): LinearColor

Red (1,0,0,1)

Returns

LinearColor

white

Static get white(): LinearColor

White (1, 1, 1, 1)

Returns

LinearColor

yellow

Static get yellow(): LinearColor

Yellow (1, 1, 0, 1)

Returns

LinearColor

Methods

addition

addition(linearColorB, outer?): LinearColor other

Addition of color values

Parameters

linearColorB LinearColorUsage: Color B added together
outer? LinearColorUsage: LinearColor object receiving result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

clone

clone(): LinearColor other

Clone the current linear color

Returns

LinearColorReturn a new linear color

division

division(linearColorB, outer?): LinearColor other

Color value division

Parameters

linearColorB LinearColorUsage: Dividing Color B
outer? LinearColorUsage: LinearColor object receiving result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

equality

equality(linearColorB, epsilon?): boolean other

Determine if two color values are equal

Parameters

linearColorB LinearColorUsage: Color B for comparison
epsilon? numberUsage: Minimum error count
default: mw.MathUtil EPSILON
range: It is recommended to have a value less than 1< Br>Type: Floating point number

Returns

booleanIs it equal. Equal returns true, unequal returns false

fromString

fromString(str): void other

Fill objects with data.

Parameters

jsonStr stringUsage: data string
range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000"

Returns

LinearColorNew LinearColor type object.

The difference between this function and another from String function is that this function is a regular function, while the other is a static function.

The calling methods are different.

Usage example: difference of call mode

ts
// This function
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;

// Static fromString function
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);
// This function
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;

// Static fromString function
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);

Parameters

str stringUsage: data string
range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000"

inequality

inequality(linearColorB, epsilon?): boolean other

Returns

booleanIs it equal. Unequal returns true, equal returns false

Multiplying color values

Parameters

linearColorB LinearColorUsage: Multiplying Color B
outer? LinearColorUsage: LinearColor object receiving result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

Parameters

linearColorB LinearColorUsage: Color B for comparison
epsilon? numberUsage: Minimum error count default: mw.MathUtil EPSILON
range: It is recommended to have a value less than 1< Br>Type: Floating point number

Returns

booleanIs it equal. Unequal returns true, equal returns false

subtraction

subtraction(linearColorB, outer?): LinearColor other

Subtract color values

Parameters

linearColorB LinearColorUsage: Subtracting color B
outer? LinearColorUsage: LinearColor object receiving result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

toString

toString(): string other

Output object properties in string form

Returns

stringObject attribute string

colorHexToLinearColor

Static colorHexToLinearColor(inColorHex, outer?): LinearColor other

Convert HexColor to LinearColor

Parameters

inColorHex stringHexColor String
range: HexColor string length
outer? LinearColorUsage: Receive converted LinearColor object default: null

Returns

LinearColorLinerColor object

colorHsvToLinearColor

Static colorHsvToLinearColor(h, s, v, outer?): LinearColor other

Convert HsvColor to LinearColor

Parameters

h numberUsage: Color tone< Range: [0,1] type: floating point number
s numberUsage: saturation< Range: [0,1] type: floating point number
v numberUsage: Brightness< Range: [0,1] 0.0 (black) to 1.0 (white) Type: Floating point number
outer? LinearColorUsage: LinearColor object receiving conversion result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

colorToLinearColor

Static colorToLinearColor(r, g, b, a?, outer?): LinearColor other

Convert current color

Parameters

r numberUsage: Color R value. Default: null
range: [0, 255] type: integer
g numberUsage: Color G value. Default: null
range: [0, 255] type: integer
b numberUsage: Color B value. Default: null
range: [0, 255] type: integer
a? numberUsage: Color transparency. Default: 255
range: [0, 255] type: integer
outer? LinearColorUsage: LinearColor object receiving conversion result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object.

fromString

Static fromString(jsonStr): LinearColor other

Generate a new object with data

The incoming format is: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000" (green)

Example usage: Create a script called NewScript, place it in the object bar, open the script, modify the original content to the following, save and run the game, and a screen UI button will be generated in the scene.

ts
@Component
 export default class NewScript extends Script {

     protected onStart(): void {
         if(SystemUtil.isClient()){
             UIService.show(NewUIScript);
         }
     }
 }

 class NewUIScript extends UIScript {

     button:StaleButton;

     protected onStart() {
         //Set whether onUpdate can be triggered every frame
         this.canUpdate = false;
         this.layer = UILayerMiddle;

         this.button = StaleButton.newObject(this.rootCanvas);

         this.button.text = "Press to turn green";
         this.button.transitionEnable = true;
         const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
         this.button.pressedImagColor = LinearColor.fromString(str);
         this.button.visibility = SlateVisibility.Visible;
         this.button.onClicked.add(() => {
             console.log("click");
         })
     }
 }
@Component
 export default class NewScript extends Script {

     protected onStart(): void {
         if(SystemUtil.isClient()){
             UIService.show(NewUIScript);
         }
     }
 }

 class NewUIScript extends UIScript {

     button:StaleButton;

     protected onStart() {
         //Set whether onUpdate can be triggered every frame
         this.canUpdate = false;
         this.layer = UILayerMiddle;

         this.button = StaleButton.newObject(this.rootCanvas);

         this.button.text = "Press to turn green";
         this.button.transitionEnable = true;
         const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
         this.button.pressedImagColor = LinearColor.fromString(str);
         this.button.visibility = SlateVisibility.Visible;
         this.button.onClicked.add(() => {
             console.log("click");
         })
     }
 }

Parameters

jsonStr stringUsage: data string
range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000"

Returns

LinearColorNew LinearColor type object.

makeFromHSV

Static makeFromHSV(h, s, v, outer?): LinearColor other

Convert byte tone saturation brightness to LinearColor

Parameters

h numberUsage: Color tone< Range: [0,1] type: floating point number
s numberUsage: saturation< Range: [0,1] type: floating point number
v numberUsage: Brightness< Range: [0,1] 0.0 (black) to 1.0 (white) Type: Floating point number
outer? LinearColorUsage: LinearColor object receiving conversion result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object

random

Static random(outer?): LinearColor other

Return a new color with random RGB values and an Alpha of 1.0

Parameters

outer? LinearColorUsage: LinearColor object receiving result default: null

Returns

LinearColorIf outer is not empty, return outer; otherwise, return a new LinearColor object