Skip to main content

Color

TypeNameInterface Description
Variablesr

Function: The red component of the color.

Variablesg

Function: The green component of the color.

Variablesb

Function: The blue component of the color.

Variablesa

Function: The transparency (alpha) component of the color.

Functionsconstructor()

Function: Create a default color with r, g, b, and a all initialized to 0.

Functionsconstructor(r: number, g: number, b: number, a: number)

Function: Creates a color with specified r, g, b, and a values.

Functionsequals(color: Color): boolean

Function: Checks whether the current color is equal to another color.

FunctionstoString(): string

Function: Returns the string representation of the current color.

Functionsclone(): 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) {
}
}

DemoColorAPI.zip

Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies