Color
Type | Name | Interface Description |
---|---|---|
Variables | r | • Function: The red component of the color. |
Variables | g | • Function: The green component of the color. |
Variables | b | • Function: The blue component of the color. |
Variables | a | • Function: The transparency (alpha) component of the color. |
Functions | constructor() | • Function: Create a default color with r, g, b, and a all initialized to 0. |
Functions | constructor(r: number, g: number, b: number, a: number) | • Function: Creates a color with specified r, g, b, and a values. |
Functions | equals(color: Color): boolean | • Function: Checks whether the current color is equal to another color. |
Functions | toString(): string | • Function: Returns the string representation of the current color. |
Functions | clone(): Color | • Function: Clone |
Examples
r, g, b, and a
const r = color.r;
const g = color.g;
const b = color.b;
const a = color.a;
constructor()
let color = new Color();
constructor(r: number, g: number, b: number, a: number)
let color = new Color(1, 0, 0, 1); // 红色
equals(color: Color): boolean
let color1 = new Color(255, 0, 0, 1);
let color2 = new Color(255, 0, 0, 1);
console.log(color1.equals(color2)); // true
toString(): string
let color = new Color(255, 0, 0, 1);
console.log(color.toString()); // "Color(r: 255, g: 0, b: 0, a: 1)"
clone(): Color
let clonedColor = color.clone();
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
let color = new APJS.Color();
color.r = 1.0;
color.g = 0.0;
color.b = 0.0;
color.a = 1.0;
console.log(color.toString());
let color2 = new APJS.Color(1.0, 0, 0, 1.0);
console.log(color2.equals(color));
let clonedColor = color2.clone();
console.log(clonedColor.toString());
}
onUpdate(deltaTime: number) {
}
}