Skip to main content

TouchUtils

Utility class for handling touch events, e.g.

TypeNameInterface Description
Static FunctionsgetPinchEmitter(): IEventEmitter

Function: Retrieves the event emitter associated with pinch.

Returns The event emitter for the pinch, which can be used to subscribe to pinch events defined in IPinchInfo.

Static FunctionsisScreenPointOnImage(screenPoint: Vector2f, image: Image): boolean

Function: Whether a normalized touch point is on an image.

Parameters

screenPoint: A normalized screen point in the range [0, 1], typically from TouchData.position. (0, 0) is the top-left corner of the screen; (1, 1) is the bottom-right corner; x increases rightward and y increases downward. This is not the pixel-based screen space used by camera conversion APIs such as Camera.screenToWorldPoint (which uses bottom-left origin with y increasing upward).

image: The image component to judge. The image should be enabled and have a valid screen transform component. It should be rendered by a camera with the Orthographic type.

Returns True if the normalized touch point is on the image, otherwise false.

Examples

getPinchEmitter(): IEventEmitter

const emitter = APJS.TouchUtils.getPinchEmitter();
const callback = (event: APJS.IEvent) => {
const pinchInfo = event.args[0] as APJS.IPinchInfo;
const { scale, angle } = pinchInfo;
// Do something with scale and angle, e.g. scale and rotate the image.
this.imageTransform.scale = new APJS.Vector2f(scale, scale);
this.imageTransform.rotation = angle * 180 / Math.PI;
}
emitter.on(0, callback); // The pinch emitter ignores eventName, so any number can be used.

isScreenPointOnImage(screenPoint: Vector2f, image: Image): boolean

let callback = (event:APJS.IEvent) => {
const touchInfo = event.args[0] as APJS.TouchData;
if (touchInfo.phase === APJS.TouchPhase.Began && APJS.TouchUtils.isScreenPointOnImage(touchInfo.position, this.imageComponent)) {
...
}
}
const globalEmitter = APJS.EventManager.getGlobalEmitter();
globalEmitter.on(APJS.EventType.Touch, callback);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
// TODO: instantiate / use TouchUtils here
}
onUpdate(deltaTime: number) {
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies