touch_id how to use this
st3v3_42 last edited by
I have a program where I am trying to control two objects on either side of the screen. Pythonista's help file suggests using the touch_id attribute. However I do not (nor can I find) any way to determine what each touch_id is nor assign it a particular ID.
If anyone could help by perhaps providing some simple code that explains how the touch_id works it would be most appreciated!
Thank You all!
polymerchm last edited by
JadedTuna last edited by
touch_idis basically an ID for every touch - you can have any amount of touches and all of them will have an unique
touch_id. It can be used in multi-touch applications to track down different touches.
JonB last edited by
A few rules that may be helpful:
touch_beganalways gets called the first time in new touches. That's a good time to add the Touch ID to a list. Sometimes you want to keep track of the initial touch location, rather than incremental changes, and this would be the time for that as well.
whenever a touch moves,
touch_movedgets called. Here you would lookup the Touch ID and update whatever logic you have that depends on the touch location. note that the order of touch calls in not guaranteed, and there is no way to know how many fingers there are on the screen except by counting how many items you have in your local touch list.
Note the incremental direction can be found by differencing the location from previous location. There is no guarantee how often this function is called. for some purposes it is useful to check for some minimum motion before taking action, in which case it works better to keep track of the initial touch yourself.
For gestures, you would probably keep a history of touch locations, or keep track of direction changes.
when a touch lifts,
touch_endedis usually called. Now would be the time to take any final action, then delete the unused touch from your touch lists. There are unfortunately exceptions to this... For instance for
panelpresentation types, pythonista grabs control of the touches when sliding back to the editor, and so
touch_endeddoes not get called. Therefore, for some applications it is advisable to have a timer that gets kicked off which clears out inactive touches, which gets restarted every time a touch moves. Hopefully this bug gets fixed, because currently touch is basically unusable in
remember that multitouch with more than 2 fingers can sometimes conflict with ios gestures, so you may want to turn those off.