Wiki
Clone wikiCore / 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:
Index | Comment |
---|---|
id | a number representing a unique identifier for the touch |
x | the x position of the touch on the viewer |
y | the y position of the touch on the viewer |
prevX | the x position of the touch on the viewer, in the previous frame |
prevY | the y position of the touch on the viewer, in the previous frame |
deltaX | the change in the x position of the touch, since the previous frame |
deltaY | the change in the y position of the touch, since the previous frame |
state | a number representing the state of the touch |
tapCount | a number representing the number of times the touch has been tapped |
touch.state
The state
of a touch can be one of the following:
state | Global variable | Comment |
---|---|---|
0 | BEGAN | Reported once when the viewer is touched. |
1 | MOVING | Reported each time the touch moves on the surface of the viewer. |
2 | ENDED | Reported 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