Can I detect holding finger down on object?

Hello,

I was wondering if I can tell when a user holds their finger down on an object for a second so I can do something. I want to create my own little popup menu for doing something with an image object. So I was hoping I can hold my finger on it and then show the menu. Is this possible? I know I can detect touch but these images are being dragged also. I forgot to mention that. Is there another way to select it then?

I even thought of putting a dotter box around the image or something to show it is selected. The only way I can do the menu is to show buttons somewhere on the screen for Edit, Remove and Clear Selection.

Thanks

Add these lines into your touch listener:

[lua]

local obj = event.target – local reference to button

if event.phase == “began” then

  obj.timer = system.getTimer()                – start a timer when bar is initally pressed

end

if event.phase == “ended” then

        local t = system.getTimer()        – get the current time

        local df = t - obj.timer        – calc time the finger was held down

        if df > 1000 then                – if finger held on object for more than a second

            – DO SOMETHING

        end

end

[/lua]

This code worked well. Thanks! Is there any way I can have it automatically do something after 1 secons like show a popup menu I build? Right now it has to wait for the touch event to end. What if I start an outside timer when the object is touched. And in 1 second check if it is still held down with a flag variable? I would clear the flag on End of the touch. This way if the timer reaches 1 second and the flag is clear it won’t do what I want. Otherwise it will. Does this make sense?

Warren

So I assume you mean when you’re not dragging the item, that you can hold down for a second or so to get a contextual menu?

Add these lines into your touch listener:

[lua]

local obj = event.target – local reference to button

if event.phase == “began” then

  obj.timer = system.getTimer()                – start a timer when bar is initally pressed

end

if event.phase == “ended” then

        local t = system.getTimer()        – get the current time

        local df = t - obj.timer        – calc time the finger was held down

        if df > 1000 then                – if finger held on object for more than a second

            – DO SOMETHING

        end

end

[/lua]

This code worked well. Thanks! Is there any way I can have it automatically do something after 1 secons like show a popup menu I build? Right now it has to wait for the touch event to end. What if I start an outside timer when the object is touched. And in 1 second check if it is still held down with a flag variable? I would clear the flag on End of the touch. This way if the timer reaches 1 second and the flag is clear it won’t do what I want. Otherwise it will. Does this make sense?

Warren

So I assume you mean when you’re not dragging the item, that you can hold down for a second or so to get a contextual menu?