Bg2TouchEvent
The Bg2TouchEvent class represents touch input events in the bg2 engine TypeScript API. It extends EventBase, providing support for event propagation control.
This class encapsulates touch interaction data and exposes the original native browser event, allowing applications to handle multi-touch input in a normalized way.
Constructor
Section titled “Constructor”constructor(touches: any, event: any)
Section titled “constructor(touches: any, event: any)”Creates a new touch event instance.
Parameters
Section titled “Parameters”touches: Collection of touch points associated with the eventevent: Original native touch event
Properties
Section titled “Properties”touches: any
Section titled “touches: any”Collection of active touch points.
This value is typically normalized relative to the canvas and may contain position and identifier data for each touch.
event: any
Section titled “event: any”Reference to the original native touch event.
Provides access to additional low-level data not exposed directly by the engine wrapper.
Utility Functions
Section titled “Utility Functions”createTouchEvent(evt: any, mainLoop: any): TouchEvent
Section titled “createTouchEvent(evt: any, mainLoop: any): TouchEvent”Creates a Bg2TouchEvent from a native browser touch event.
This function:
- Extracts touch information relative to the canvas
- Normalizes touch coordinates
- Returns a new
Bg2TouchEventinstance
Usage Notes
Section titled “Usage Notes”- Used in
AppControllercallbacks such astouchStart,touchMove, andtouchEnd - Supports multi-touch interactions
- Touch coordinates are normalized relative to the canvas
- Use
eventfor platform-specific or low-level data if required
Example
Section titled “Example”touchStart(evt: Bg2TouchEvent) { console.log("Touch start:", evt.touches);}
touchMove(evt: Bg2TouchEvent) { console.log("Touch move:", evt.touches);}
touchEnd(evt: Bg2TouchEvent) { console.log("Touch end");}