Button sticks

I am using the “Better Buttons” code, created for GameDevNation.
I have two types of buttons, one that changes to an alpha of 0.5 when pressed, and one that changes to an alpha of 0 when pressed (with a depressed-button image underneath it).

Both types of buttons go back to alpha of 1 when I slide my finger off of it. However: if my finger is right on the edge of the button, and I quickly slide it barely outside the button, the button consistently sticks in the lower alpha state.

That is the undesirable effect that I get.

Interestingly, the 0.5 alpha button can “recover” by “playing nice” with it, but the 0 alpha type is permanently stuck that way, and is unresponsive. (I have a vague idea of why that is so).

I would like to fix both types of buttons if possible. If it’s just an issue of computer reaction time that is unavoidable, I can accept that. But please tell me that’s the case.

But if anyone is familiar with the “Better Buttons” code and knows how to resolve this, please let me know. I would hate to get a 1 star on a 5-star app because of this, you know it happens!

Thanks!
Dane [import]uid: 117490 topic_id: 22585 reply_id: 322585[/import]

I think this thread could hold the answer : http://developer.anscamobile.com/forum/2012/01/24/what-do-when-touch-target-lost [import]uid: 84637 topic_id: 22585 reply_id: 90004[/import]

For the record, that thread basically explained how the button works in general, but doesn’t address my problem.

The good news is I found a solution. Again, the problem was starting the finger touch right on the boundary of the button, quickly moving the finger slightly off the button and releasing.

This is part of the “Better Buttons” code, and I added the commented line:

[lua]local function buttonTouched(e)
local t = e.target
if e.phase == “began” then
t.alpha = 0.75
t.active = true
display.getCurrentStage():setFocus(t)
elseif e.phase == “moved” and t.active then
if ptInside(t, e.x, e.y) then
t.alpha = 0.75
else
t.alpha = 1
end
else
display.getCurrentStage():setFocus(nil)
end
if e.phase == “ended” and t.active then
t.active = false
if ptInside(t, e.x, e.y) then
t.alpha = 1
t.action()
else --added the else statement
t.alpha = 1 – added this line to prevent buttons from getting stuck.
end
end

end
end[/lua] [import]uid: 117490 topic_id: 22585 reply_id: 90046[/import]

dogfish, thanks, I’ll take a look at updating that code later, and as an enhancement on your enhancement you can cut out the else and just do that chunk of the code like this:

(Untested code, just off the top of my head.)

[lua] if e.phase == “ended” and t.active then
t.active = false
t.alpha = 1
if ptInside(t, e.x, e.y) then
t.action()
end
end
[/lua]

If the t.alpha is going to happen no whether ptInside returns true or false, just move it outside that if statement.

Thanks for sharing that enhancement with everyone.

Jay [import]uid: 9440 topic_id: 22585 reply_id: 90056[/import]