TouchPointer

View source

Represents one active touch contact and its current and previous positions.

TouchPlugin creates and updates pointers stored in Touches. At touch start, TouchPointer#position and TouchPointer#lastposition both receive the start position. On a later move, the previous current position is copied to TouchPointer#lastposition before TouchPointer#position receives the new event position, so subtracting the vectors gives the movement for that update. A touch end or cancellation removes the pointer from Touches without resetting its fields.

TouchPointer#id is the compact slot assigned by Touches#set; it is not the browser’s pointerId. Read the pointer returned by Touches#get or Touches#getActive rather than updating its history directly.

Examples

import { Touches } from '@wimaengine/touch'

function readFirstTouch(world) {
  const pointer = world.getResource(Touches).getFirst()
  if (!pointer) return

  console.log(pointer.id)
  console.log(pointer.position.x - pointer.lastposition.x)
}

Constructor


constructor(id: number)

View source

Creates a touch pointer with an initial compact ID.

Both position vectors start at (0, 0). When the pointer is created by TouchPlugin, the plugin passes 0 and Touches#set later assigns the actual compact slot. The constructor does not receive or translate a browser pointerId.

Parameters

NameDescriptionDefault
id

Initial engine-side ID; Touches#set may replace it.

—

Properties


readonlyid: number

View source

Compact engine slot assigned to this pointer by Touches#set.

The constructor initializes this value from its argument. When Touches#set stores the pointer, it overwrites the value with the slot mapped from the browser pointer ID.

Default: 0

position: Vector2

View source

Current position of the touch in the pointer event’s coordinate space.

TouchPlugin copies the latest matching pointer-move position here. On a new pointer this vector is initialized to zero until the plugin copies the start event into it.

Default: ...

lastposition: Vector2

View source

Position recorded before the latest touch move.

TouchPlugin copies TouchPointer#position here before applying a new move. At touch start it copies the initial position here as well, so the first frame’s position delta is zero. This field is exposed as TouchPointer#lastposition in the public API.

Default: ...