Texture
APJS Script API reference for the Texture class.
| Type | Name | Interface Description |
|---|---|---|
| Variables | enableMipmap: boolean | • Function: Gets whether mipmap is enabled for the texture. Returns Whether mipmap is enabled. |
| Variables | filterMag: FilterMode | • Function: Gets the magnification filter mode of the texture. Returns The current magnification filter mode. |
| Variables | filterMin: FilterMode | • Function: Gets the minimization filter mode of the texture. Returns The current minimization filter mode. |
| Variables | filterMipmap: FilterMipmapMode | • Function: Gets the mipmap mode for the texture. Returns The current mipmap mode. |
| Variables | maxAnisotropy: number | • Function: Gets the maximum anisotropy level of the current texture. Returns The maximum anisotropy level as a number. |
| Variables | wrapModeR: WrapMode | • Function: Gets the wrap mode of the R dimension. Returns The current wrap mode for the R dimension. |
| Variables | wrapModeS: WrapMode | • Function: Get the wrap mode of the S dimension. Returns The current wrap mode for the S dimension. |
| Variables | wrapModeT: WrapMode | • Function: Get the wrap mode of the T dimension. Returns The current wrap mode for the T dimension. |
| Functions | constructor() | |
| Functions | getControl(): 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. |
| Functions | getDepth(): number | • Function: Retrieves the depth of the source texture. Returns The depth of the texture as a number. |
| Functions | getHeight(): number | • Function: Retrieves the height of the texture. Returns The height of the texture as a number. |
| Functions | getWidth(): 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);
}
}