Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
touch_id how to use this
-
Hello
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!
-
-
Hey there.
touch_id
is basically an ID for every touch - you can have any amount of touches and all of them will have an uniquetouch_id
. It can be used in multi-touch applications to track down different touches. -
A few rules that may be helpful:
-
touch_began
always 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_moved
gets 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_ended
is 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 forpanel
presentation types, pythonista grabs control of the touches when sliding back to the editor, and sotouch_ended
does 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 inpanel
style presentation. -
remember that multitouch with more than 2 fingers can sometimes conflict with ios gestures, so you may want to turn those off.
-