Touch

Reference ❯ Detecting and Reacting to Touches on the Screen

Handling Touches

CurrentTouch top ↑

Syntax

CurrentTouch

This global variable always represents the current single touch on the screen. It is a touch datatype, see the related items for more information.

Examples

function draw() background( 0 ) fill( 255, 0, 0 ) ellipse( CurrentTouch.x, CurrentTouch.y, 300 ) end

touch top ↑

Syntax

touch.id
touch.pos
touch.prevPos
touch.precisePos
touch.precisePrevPos
touch.delta
touch.force
touch.maxForce
touch.altitude
touch.azimuth
touch.azimuthVec
touch.type
touch.state
touch.tapCount

This type represents data about a single touch on the screen.

id

int, a unique identifier for this touch

pos

vec2, specifies the position of the touch on the screen

prevPos

vec2, specifies the position, from the previous frame, of the touch on the screen

precisePos

vec2, specifies the precise position of the touch on the screen (when available, for example, when using a stylus)

precisePrevPos

vec2, specifies the precise position, from the previous frame, of the touch on the screen (when available, for example, when using a stylus)

delta

vec2, specifies the delta since the last frame, the amount the touch has moved

force

float, when available, specifies the force of the touch

maxForce

float, when available, specifies the maximum possible force of a touch

altitude

float, stylus only, angle in radians of the stylus with the surface of the screen. A value of 0 indicates the stylus is parallel to the screen, a value of Pi/2 indicates a stylus perpendicular to the screen

azimuth

float, stylus only, angle in radians of the direction in which the stylus is pointing

azimuthVec

vec2, stylus only, a unit vector which points in the direction of the stylus

type

the type of the touch, can be DIRECT, INDIRECT, or STYLUS

state

the state of the touch, can be BEGAN, MOVING, ENDED or CANCELLED

tapCount

how many times the touch has been tapped

Touch States

BEGAN top ↑

Syntax

BEGAN

This state occurs when a touch first begins

MOVING top ↑

Syntax

MOVING

This state occurs when a touch changes position but the user's finger remains on the screen

ENDED top ↑

Syntax

ENDED

This state occurs when a user lifts their finger from the screen

CANCELLED top ↑

Syntax

CANCELLED

This state occurs when the system interrupts the touch for some reason (e.g., system alert, notification window slid down, multitasking entered). This state can generally be handled similarly to ENDED.

Touch Types

DIRECT top ↑

Syntax

DIRECT

Direct touches occur when the user's finger touches the screen

INDIRECT top ↑

Syntax

INDIRECT

Indirect touches are generated by touch input devices that are separate from the screen. For example, a remote pointing device

STYLUS top ↑

Syntax

STYLUS

A stylus touch occurs when a stylus interacts with the device's screen