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.x touch.y touch.prevX touch.prevY touch.deltaX touch.deltaY touch.state touch.tapCount

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

id

int, a unique identifier for this touch

x

float, specifies the x position of the touch on the screen

y

float, specifies the y position of the touch on the screen

prevX

float, specifies the x position, from the previous frame, of the touch on the screen

prevY

float, specifies the y position, from the previous frame, of the touch on the screen

deltaX

float, specifies the x delta since the last frame, the amount the touch has moved

deltaY

float, specifies the y delta since the last frame, the amount the touch has moved

state

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

tapCount

how many times the touch has been tapped