TouchPlugin

View source

ExtendsPlugin

Adds touch input tracking to an App.

The plugin provides a Touches resource in the app’s default world. It tracks touch contacts from pointer input and ignores pointers whose type is not touch. Read the resource with world.getResource(Touches) to inspect the active contacts.

Each active contact is represented by a TouchPointer. A touch start creates a pointer with its current and previous positions set to the start position. On later moves, the previous position is retained in lastposition while the current position follows the contact. A pointer is removed when its touch ends or is canceled.

The plugin consumes typed PointerDown, PointerMove, PointerUp, and PointerCancel events from WindowPlugin. Only events whose pointerType is touch affect the touch resource.

The plugin requires CorePlugin, ReflectPlugin, and WindowPlugin. Register these dependencies before registering this plugin; it does not install them automatically.

Examples

import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'
import { TouchPlugin, Touches } from '@wimaengine/touch'
import { WindowPlugin } from '@wimaengine/window'

const app = new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new WindowPlugin({ initPrimaryWindow: false }))
  .registerPlugin(new TouchPlugin())
  .run()

const touches = app.getWorld().getResource(Touches)
console.log(touches.getActive())

Constructor


constructor()

Methods


register(app: App): void

View source

Adds touch input state to the app’s default world.

The app gains a Touches resource for reading active TouchPointer values.

Parameters

NameDescriptionDefault
app

App to configure.

—