What is the difference between touch and tap events? What I would like to do, is have a line of text the user can drag and place where they like and also be able to change the font. Right now I have a “touch” event on the text which allows the user to drag and drop the text where they like (works great). Now I would like to have another event on the same text where the user just taps it and a new scene will be displayed showing some text boxes where the user can change the text size. Will this work if I have the second event on “tap” and the drag event on “touch” (which works great already)? Also, when a line of text is selected I call a function which brings the checkbox scene to front and hides the others, then from this scene if the user checks a checkbox a function is called changing the text to the corresponding font size. How do I tell the font changing function which text has been selected. I would like to do “local text = event.target” but that would give the checkbox not the original text that was selected. Any ideas how to do that? Thanks. [import]uid: 152084 topic_id: 27182 reply_id: 327182[/import]
I doubt the two will work together.
Technically a touch event records finger down, finger move and finger up, reporting to you for each of those events and the x, y that they happened.
Tap doesn’t assume any movement, nor does it really care about beginning, just the end event. I find that tap events are pokey. Meaning you have to get your finger off the button rather quickly for it to register as a tap.
But since both events are looking for a touch and a release, I don’t think the software can distinguish between the two.
You could program your own tap into your touch event: Touch reports the time of the events, so if the touch is less than say 250ms and the x and y didn’t move more than a few pixels, do whatever you want for the tap event, if its longer or the movement is greater than 5px then treat it as a touch and drag. [import]uid: 19626 topic_id: 27182 reply_id: 110363[/import]
Ok, so something like:
[lua] local text = event.target
if (event.x - text.x) > 3 then
–do touch
else
–do tap
end[/lua]
Also, any ideas how I can get the select text in the second function.
How do I get the touch time? [import]uid: 152084 topic_id: 27182 reply_id: 110364[/import]
look up event.touch in the api documentation.
event.target.text to get the text.
Since you are assigning event.target to a variable called text, you could reference it as:
text.text. [import]uid: 19626 topic_id: 27182 reply_id: 110367[/import]
I don’t think you understand my question. I have two events:
-
The 1st touch event - (this event is triggered when a textField called foo is touched) this event calls the function texttouchHandler. Inside this function a new group is displayed containing checkboxes.
-
The 2nd touch event is triggered when a checkbox is touched. This event should change the font size of foo.
I know how to change the font size, I just don’t know how to access foo from the 2nd event handler.
any ideas? [import]uid: 152084 topic_id: 27182 reply_id: 110374[/import]
I would do the lazy way and create a local variable at the top of your .lua file, maybe call it:
local activeTextField
then in your texttouchHandler function, set activeTextField to be the field the texttouchHandler is working with.
When you get into your check box event handlers, then activeTextField should be the last text field accessed.
[import]uid: 19626 topic_id: 27182 reply_id: 110510[/import]
haha thanks, that is a very simple and good idea. I never thought about doing it that way. [import]uid: 152084 topic_id: 27182 reply_id: 110533[/import]
works good [import]uid: 152084 topic_id: 27182 reply_id: 110534[/import]
You say : “Touch reports the time of the events”
How ?
event.time reports the time since app launches, so I have to do some sort of record time began or is there really a shorcut for getting the event.touch time ?
Thx [import]uid: 9328 topic_id: 27182 reply_id: 112018[/import]
Yes, you have to record the time of the first touch event and then calculate the difference in time on the second touch…
local lastTouch = 0
local touchHandler(event) {
if event.phase == "ended" then
if (event.time - lastTouch) \< 500 then
-- do your code for a double tap
end
lastTouch = event.time
end
end
Or something similar. [import]uid: 19626 topic_id: 27182 reply_id: 112056[/import]
Thx for your answer rob
[import]uid: 9328 topic_id: 27182 reply_id: 112064[/import]