Wiki

Clone wiki

Core / touch

touch userdata

Introduction

Codea's in-app reference documents most of the touch userdata. The userdata value represents read only data about a single touch on the viewer.

Getting information about a touch

Indexing can be used to get information about a touch, as summarised in the table below:

IndexComment
ida number representing a unique identifier for the touch
xthe x position of the touch on the viewer
ythe y position of the touch on the viewer
prevXthe x position of the touch on the viewer, in the previous frame
prevYthe y position of the touch on the viewer, in the previous frame
deltaXthe change in the x position of the touch, since the previous frame
deltaYthe change in the y position of the touch, since the previous frame
statea number representing the state of the touch
tapCounta number representing the number of times the touch has been tapped

touch.state

The state of a touch can be one of the following:

stateGlobal variableComment
0BEGANReported once when the viewer is touched.
1MOVINGReported each time the touch moves on the surface of the viewer.
2ENDEDReported once when touch leaves the viewer.

touch.tapCount

In some cases, the touch.id is preserved between taps. In other cases, each tap has a distinct touch.id but the touch.tapCount increases with each tap.

In some cases, where touch.state is ENDED, the touch.tapCount is zeroed. In other cases, the touch.tapCount is equal to what it was before the touch.state was ENDED.

Functions

The userdata supports tostring() to produce nicely-formatted output. Consequently, print() also generates nicely-formatted output.

Updated