Move-out event... how to do?

Currently, all touch events only happen when the finger is over whatever you are touching…

If you move your finger out of it, no further events happen until you move it back.

A “solution” would be using focus. But focus only help in the sense you can detect “ended” phase and thus at least make the touch-able object do not break too much…

But how I detect that I moved my finger out of a object? I want to return to a object initial state as soon as you move the finger away from it. [import]uid: 142895 topic_id: 29033 reply_id: 329033[/import]

I presume you don’t anticipate the user lifting and moving their finger and in fact slides out of the actual control zone on the screen, for example an on-screen joystick? Why not hold a reference as a scoped variable that tells you the last control the user clicked, or touched, and set that to nil when you no longer detect a touch, in the mean time your touch event can be used to gain the distance moved from your UI control with each movement? [import]uid: 51222 topic_id: 29033 reply_id: 116836[/import]

If I understand you correctly, you want to release the button when the touch moves outside its bounds? If so, then something like this will do it:

Edit: I just remembered that this routine is used for some code where I take action when the button is pressed, and no action when it is released. For “normal” button behavior, where you want to take action when the button is released while the touch is within the bounds, but cancel if the touch is moved outside the button’s bounds, then this wouldn’t work. You would want to treat the movement out of bounds as a “cancel” of the event.

[lua]local function buttonTouch(event)
local phase = event.phase
local target = event.target
local bounds = target.contentBounds
if ( “began” == phase ) then
display.getCurrentStage():setFocus(target)
target.isFocus = true
return 1 --pressed
elseif ( target.isFocus ) then
if ( “moved” == phase ) then
–If moved, and no longer within button bounds, return release.
if ( (event.x < bounds.xMin) or (event.x > bounds.xMax) or
(event.y < bounds.yMin) or (event.y > bounds.yMax) ) then
display.getCurrentStage():setFocus(nil)
target.isFocus = false
return 2 --released
else
–Moved but still inside button bounds.
return 0 --no change
end
else
–Anything else is a release.
display.getCurrentStage():setFocus(nil)
target.isFocus = false
return 2 --released
end
end
return 0 --no change
end
_[/lua]
[import]uid: 22076 topic_id: 29033 reply_id: 116844[/import]