Skip to main content

Texture

APJS Script API reference for the Texture class.

TypeNameInterface Description
VariablesenableMipmap: boolean

Function: Gets whether mipmap is enabled for the texture.

Returns Whether mipmap is enabled.

VariablesfilterMag: FilterMode

Function: Gets the magnification filter mode of the texture.

Returns The current magnification filter mode.

VariablesfilterMin: FilterMode

Function: Gets the minimization filter mode of the texture.

Returns The current minimization filter mode.

VariablesfilterMipmap: FilterMipmapMode

Function: Gets the mipmap mode for the texture.

Returns The current mipmap mode.

VariablesmaxAnisotropy: number

Function: Gets the maximum anisotropy level of the current texture.

Returns The maximum anisotropy level as a number.

VariableswrapModeR: WrapMode

Function: Gets the wrap mode of the R dimension.

Returns The current wrap mode for the R dimension.

VariableswrapModeS: WrapMode

Function: Get the wrap mode of the S dimension.

Returns The current wrap mode for the S dimension.

VariableswrapModeT: WrapMode

Function: Get the wrap mode of the T dimension.

Returns The current wrap mode for the T dimension.

Functionsconstructor()

FunctionsgetControl(): TextureProvider

Function: Retrieves the control associated with the texture. In runtime, it checks and loads the JS asset if necessary, then retrieves the JS asset by GUID from the map. If the JS asset is found, it returns the asset as a TextureProvider; otherwise, it returns the internal __control property.

Returns The control associated with the texture, either as a TextureProvider or the internal __control property.

FunctionsgetDepth(): number

Function: Retrieves the depth of the source texture.

Returns The depth of the texture as a number.

FunctionsgetHeight(): number

Function: Retrieves the height of the texture.

Returns The height of the texture as a number.

FunctionsgetWidth(): number

Function: Retrieves the width of the texture.

Returns The width of the texture as a number.

Examples

constructor()

let obj = new APJS.Texture();

Use Case

Example 1 — Cycle through a @serializeProperty Texture[] array on an Image component at a configurable interval.

@component()
export class TextureCycler extends APJS.BasicScriptComponent {
@serializeProperty
private textures: APJS.Texture[] = [];
@serializeProperty
private displayObject: APJS.SceneObject;
@serializeProperty
private interval: number = 0.05;

private displayImage: APJS.Image;
private shuffled: APJS.Texture[] = [];
private currentIndex: number = 0;
private timer: number = 0;
private running: boolean = false;

onStart(): void {
this.displayImage = this.displayObject.getComponent("Image") as APJS.Image;
this.startCycling();
APJS.EventManager.getGlobalEmitter().on(APJS.EventType.Touch, this.onTouch);
}

private startCycling(): void {
this.shuffled = [...this.textures].sort(() => Math.random() - 0.5);
this.currentIndex = 0;
this.timer = 0;
this.running = true;
}

private onTouch = (event: APJS.IEvent) => {
const touch = event.args[0] as APJS.TouchData;
if (touch.phase === APJS.TouchPhase.Began) {
if (this.running) {
this.running = false;
} else {
this.startCycling();
}
}
};

onUpdate(deltaTime: number): void {
if (!this.running || !this.displayImage) return;
this.timer += deltaTime;
if (this.timer >= this.interval) {
this.displayImage.texture = this.shuffled[this.currentIndex];
this.currentIndex = (this.currentIndex + 1) % this.shuffled.length;
this.timer = 0;
}
}

onDestroy(): void {
APJS.EventManager.getGlobalEmitter().off(APJS.EventType.Touch, this.onTouch);
}
}

Example 2 — Dynamically update Text content and Image texture at runtime using @serializeProperty bindings

@component()
export class DynamicTextUpdate extends APJS.BasicScriptComponent {
@serializeProperty
private labelObject: APJS.SceneObject;

@serializeProperty
private counterObject: APJS.SceneObject;

@serializeProperty
private iconObject: APJS.SceneObject;

@serializeProperty
private textures: APJS.Texture[] = [];

private labelText: APJS.Text;
private counterText: APJS.Text;
private iconImage: APJS.Image;
private count: number = 0;
private currentTextureIndex: number = 0;

private onTouchEvent = (event: APJS.IEvent) => {
const touchInfo = event.args[0] as APJS.TouchData;
if (touchInfo.phase === APJS.TouchPhase.Began) {
this.count++;
if (this.counterText) {
this.counterText.text = this.count.toString();
}

// Cycle through textures on tap
if (this.iconImage && this.textures.length > 0) {
this.currentTextureIndex = (this.currentTextureIndex + 1) % this.textures.length;
this.iconImage.texture = this.textures[this.currentTextureIndex];
}
}
};

onStart(): void {
this.labelText = this.labelObject.getComponent("Text") as APJS.Text;
this.counterText = this.counterObject.getComponent("Text") as APJS.Text;
this.iconImage = this.iconObject.getComponent("Image") as APJS.Image;

if (this.labelText) {
this.labelText.text = "Tap to count";
}
if (this.counterText) {
this.counterText.text = "0";
}

APJS.EventManager.getGlobalEmitter().on(APJS.EventType.Touch, this.onTouchEvent);
}

onDestroy(): void {
APJS.EventManager.getGlobalEmitter().off(APJS.EventType.Touch, this.onTouchEvent);
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies