User Interface(ui.lua) button getting stuck in "push/press" phase

When a user clicks a button in my game to go to the levels it does the usual “push/press” effect. Recently I added some code to take the button out of focus if it gets dragged outside a certain boundary. It work fine other than the fact the button stays in the pressed/pushed phase. Heres my code:

[lua] local world3Btn

local function onworld3Touch ( event )
if event.phase == “began” then

display.getCurrentStage():setFocus( event.target )
event.target.isFocus = true

print(“touched”)

elseif event.target.isFocus then
if event.phase == “moved” then

local dx = math.abs( event.x - event.xStart )

local dy = math.abs( event.y - event.yStart )

if dx > 25 or dx < -35 then
event.phase = “cancelled”
print ( "id = " … event.x … ", phase = " … event.phase )
end

print( “Move Phase” )
print( “Move Ended” )

elseif event.phase == “ended” or event.phase == “cancelled” then

display.getCurrentStage():setFocus( nil )
event.target.isFocus = false

director:changeScene(“loadworld”)
print(“Moving on”)
end

end
end[/lua] [import]uid: 46082 topic_id: 34010 reply_id: 334010[/import]

I doubt that this:

event.phase = "cancelled"  

is doing anything for you. First, event is set every time the button gets an event. Just changing the value doesn’t effect the event in any way. It’s not a two-way conversation. In otherwords, nothing is listening to that event table after the event is generated except for your function. Actually, I take that back… You are not doing a “return true” at the end of the function so the object behind your button may be getting a cancelled phase when it get the propgated event.

I suspect you’re trying to make the “elseif event.phase == “ended” or event.phase == “cancelled” then” clause trigger and this won’t do it. The decision about what clause gets executed is decided before anything you do in that clause. In other words those if’s and elseif’s are based on the value before the if starts, not after it’s being processed.

[import]uid: 199310 topic_id: 34010 reply_id: 135246[/import]

Actually it works just as I want it to other than the fact the button doesn’t seem to “release”. My intent is for the button to “snap” back to its original position after being dragged for a certain distance and look as if it was never touched. I’ll post a sample project of what i’m doing in about 30 min. Thanks for your help. [import]uid: 46082 topic_id: 34010 reply_id: 135257[/import]

Here is a sample project: http://speedy.sh/N8px3/DraggingButton.zip

[import]uid: 46082 topic_id: 34010 reply_id: 135260[/import]

There’s nothing to stop you from changing the event.phase as you did, but Rob’s point is that the event is only executed once, and it already detected event.phase == “moved”, so it can’t and won’t go on to check "elseif event.phase == “cancelled”. And that event is thrown out after your listener gets through with it, so changing the phase data on your own doesn’t actually accomplish anything.

I suppose if you changed the “elseif” into “if” it might check that way, but it’s hard to say how timing works in that function.

Anyway, there’s no manual way to force iOS to “release” since it’s always detecting touch input. What you should probably use instead are active flags to tell you whether the button is usable or not, ie: button.isActive = true [import]uid: 41884 topic_id: 34010 reply_id: 135261[/import]

I’ve tried setting button.isActive = true/false when the button moves beyond my set limits, but it didn’t work.
When I use:
[lua]event.phase = “cancelled”[/lua]
it reacts like I want, but the button doesn’t return to its original state. The sample project I posted illustrates the problem better than I can explain. I’ve tried everything I can think of and am out of solutions. Thanks for everyones help. [import]uid: 46082 topic_id: 34010 reply_id: 135266[/import]

Ive found I get the same result when using event.phase “ended”. I think im on the right track, but I cant get the button to pop back up after being pressed. [import]uid: 46082 topic_id: 34010 reply_id: 135281[/import]

If your using ui.lua and press and hold a button and then drag off it, the button does not receive a released or ended phase.

I posted about this ages ago and got no replies, so I ended up modifying ui.lua.

I commented out this if/end statement on line 85 -

if isWithinBounds then

After doing this my buttons never got stuck in the down phase anymore.

Dave [import]uid: 117617 topic_id: 34010 reply_id: 135307[/import]

I doubt that this:

event.phase = "cancelled"  

is doing anything for you. First, event is set every time the button gets an event. Just changing the value doesn’t effect the event in any way. It’s not a two-way conversation. In otherwords, nothing is listening to that event table after the event is generated except for your function. Actually, I take that back… You are not doing a “return true” at the end of the function so the object behind your button may be getting a cancelled phase when it get the propgated event.

I suspect you’re trying to make the “elseif event.phase == “ended” or event.phase == “cancelled” then” clause trigger and this won’t do it. The decision about what clause gets executed is decided before anything you do in that clause. In other words those if’s and elseif’s are based on the value before the if starts, not after it’s being processed.

[import]uid: 199310 topic_id: 34010 reply_id: 135246[/import]

Actually it works just as I want it to other than the fact the button doesn’t seem to “release”. My intent is for the button to “snap” back to its original position after being dragged for a certain distance and look as if it was never touched. I’ll post a sample project of what i’m doing in about 30 min. Thanks for your help. [import]uid: 46082 topic_id: 34010 reply_id: 135257[/import]

Here is a sample project: http://speedy.sh/N8px3/DraggingButton.zip

[import]uid: 46082 topic_id: 34010 reply_id: 135260[/import]

There’s nothing to stop you from changing the event.phase as you did, but Rob’s point is that the event is only executed once, and it already detected event.phase == “moved”, so it can’t and won’t go on to check "elseif event.phase == “cancelled”. And that event is thrown out after your listener gets through with it, so changing the phase data on your own doesn’t actually accomplish anything.

I suppose if you changed the “elseif” into “if” it might check that way, but it’s hard to say how timing works in that function.

Anyway, there’s no manual way to force iOS to “release” since it’s always detecting touch input. What you should probably use instead are active flags to tell you whether the button is usable or not, ie: button.isActive = true [import]uid: 41884 topic_id: 34010 reply_id: 135261[/import]

I’ve tried setting button.isActive = true/false when the button moves beyond my set limits, but it didn’t work.
When I use:
[lua]event.phase = “cancelled”[/lua]
it reacts like I want, but the button doesn’t return to its original state. The sample project I posted illustrates the problem better than I can explain. I’ve tried everything I can think of and am out of solutions. Thanks for everyones help. [import]uid: 46082 topic_id: 34010 reply_id: 135266[/import]

Ive found I get the same result when using event.phase “ended”. I think im on the right track, but I cant get the button to pop back up after being pressed. [import]uid: 46082 topic_id: 34010 reply_id: 135281[/import]

If your using ui.lua and press and hold a button and then drag off it, the button does not receive a released or ended phase.

I posted about this ages ago and got no replies, so I ended up modifying ui.lua.

I commented out this if/end statement on line 85 -

if isWithinBounds then

After doing this my buttons never got stuck in the down phase anymore.

Dave [import]uid: 117617 topic_id: 34010 reply_id: 135307[/import]