Skip to main content

TouchData

The touch data is carried by touch event, record the info of one touch point.

TypeNameInterface Description
Variablesforce: number

Function: Get the force of the touch. Typically a normalized value between 0 and 1.

Variablesphase: TouchPhase

Function: The touch phase of this touch.

Returns The current phase of the touch as a TouchPhase enum value.

Variablesposition: Vector2f

Function: Gets the position of the touch in normalized screen coordinates. Coordinates use the range [0, 1]. x is horizontal (0 = left, 1 = right). Important: y is in a flipped coordinate space — 0 = top of screen, 1 = bottom. This is the opposite of standard screen space and world space (where y increases upward). Always flip y before using the position for world-space calculations or UI placement:

Returns Normalized position of the touch as a Vector2f. Value range: x ∈ [0, 1], y ∈ [0, 1] (0 = top, 1 = bottom).

VariablestouchCount: number

Function: Get the number of active touches.

Returns The total number of active touches on the screen.

VariablestouchId: number

Function: Get the unique identifier for this touch.

Returns The unique ID of the touch, useful for tracking individual touches in multi-touch scenarios.

Functionsconstructor()

Examples

position: Vector2f

const touch = event.args[0] as APJS.TouchData;
const touchPos = new APJS.Vector2f(touch.position.x, 1.0 - touch.position.y);
const screenPos = touchPos.clone().multiply(new APJS.Vector2f(720, 1280));

constructor()

let obj = new APJS.TouchData();

Use Case

Example 1 — Tap screen to toggle object visibility on/off

@component()
export class TapToggleVisibility extends APJS.BasicScriptComponent {
private touchCallback: (event: APJS.IEvent) => void;
private isVisible: boolean = true;

onStart(): void {
this.touchCallback = (event: APJS.IEvent) => {
const touchInfo = event.args[0] as APJS.TouchData;
if (touchInfo.phase === APJS.TouchPhase.Began) {
this.isVisible = !this.isVisible;
this.getSceneObject().enabled = this.isVisible;
}
};
APJS.EventManager.getGlobalEmitter().on(APJS.EventType.Touch, this.touchCallback, this);
}

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

Example 2 — Toggle visibility of all children in a container object on tap

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

private childrenVisible: boolean = true;

private onTouchEvent = (event: APJS.IEvent) => {
const touchInfo = event.args[0] as APJS.TouchData;
if (touchInfo.phase === APJS.TouchPhase.Began) {
this.childrenVisible = !this.childrenVisible;
const children = this.container.getChildren();
for (const child of children) {
child.enabled = this.childrenVisible;
}
}
};

onStart(): void {
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