Skip to content
bg2 engine

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.


Creates a new touch event instance.

  • touches: Collection of touch points associated with the event
  • event: Original native touch event

Collection of active touch points.

This value is typically normalized relative to the canvas and may contain position and identifier data for each touch.


Reference to the original native touch event.

Provides access to additional low-level data not exposed directly by the engine wrapper.


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 Bg2TouchEvent instance

  • Used in AppController callbacks such as touchStart, touchMove, and touchEnd
  • Supports multi-touch interactions
  • Touch coordinates are normalized relative to the canvas
  • Use event for platform-specific or low-level data if required

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");
}