Touched, touching, good touch/bad touch, I'm telling...

So… I have a button. I touch my button and it calls my btn.action function as I end touch, great. I can also do good with start touch and moving…

But I need a “is touching” or “touching” hook so if I hold the button it will continue to trigger.

I assume I am SOL on this because it’s not documented… But…

Best practice would be: on start touch set a flag, on end touch clean flag and in “draw” if flag is on do action???

Make sense?

That’s how I would do it.

Similarly, several apps on the market have the function of touching and holding a button, icon, etc. which then opens another screen for further options.

This would be cool to implement.

something like?

if touch.state == BEGAN and touchOnButton() then
    isTouching = true
elseif touch.state == ENDED and touchOnButton() then
    isTouching = false
end

That is sort of what I did.

but more like this:

if touch.state == BEGAN and touchOnButton() then
    isTouching = true
elseif touch.state == ENDED  then
    isTouching = false
end

if you keep the touchOnButton() in place then if you slide off the button the push never ends.

My touch library handles this sort of thing fairly well, particularly with regard to assigning touches to particular objects and tracking that through the touch’s lifetime.

@Andrew_Stacey I was thinking if you make sure all controls/objects(classes in my case) have a x,y,w,h it could create some sort of standard routine to handle touching.

sounds like you already have. I really wish apple would allow better collaboration and code sharing.

For now I allow each class to handle there own events, both draw and touch.

@wrmichael A full description of my system is at http://loopspace.mathforge.org/discussion/10/touch-tutorial. You can get the file from http://www.math.ntnu.no/~stacey/code/CodeaLibrary/Touch.lua. As this is the most basic of my library code, you don’t need any of my other libraries to use it.