TouchUtils
Utility class for handling touch events, e.g.
| Type | Name | Interface Description |
|---|---|---|
| Static Functions | getPinchEmitter(): 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 Functions | isScreenPointOnImage(screenPoint: Vector2f, image: Image): boolean | • Function: Whether a normalized touch point is on an image. Parameters • • 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) {
}
}