How to lose focus when moving finger out of a widget button?

Hello guys,

I have a fire button (widget) that keeps firing if i keep my finger on the button then moving it out of the button area (custom graphic) I guess it is because the button misses the “release” event if I i move my finger out of the button graphic while still touching the screen. I am sure it is an issue with focus but how do we deal with focus and widget button since we cannot use focus and (self,event) like in this code:

[lua]local function onObjectTouch( self, event )
if event.phase == “began” then

– specify the global touch focus
display.getCurrentStage():setFocus( self )
self.isFocus = true

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

– do something here; or not

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

– reset global touch focus
display.getCurrentStage():setFocus( nil )
self.isFocus = nil
end
end

return true
end[/lua]
Is there something like this for button widget? Here my code which works but like I said, keep firing if I move my finger (but keep it touching the screen) If I actually remove my finger then it react normally (stop firing)

[lua]local function btFireTouch(event)

local phase = event.phase

if “release” == phase then

– stop firing the gun (disable the gun)

gunEnable = false
gunFire = false

elseif “press” == phase then

– start firing the gun (enabling the gun and updating the firing)

gunEnable = true
gunFire = true
updateWeapon()

end

return true

end[/lua]

Thanks so much for any pointers. Maybe the only solution will be to add a local “touch” listener to the fire button and then use the “focus” management as shown on the top of this post? I will love to still use widget buttons (since I have many buttons and uses multi touch…)

THANKS!

Mo

[import]uid: 100814 topic_id: 30771 reply_id: 330771[/import]

Hi again

I am still looking at ways to remove focus on a widget button. It seems to me that a widget button should lose focus when the finger is no longer on it. Right now it seems that if you keep your finger on the button and then move your finger away from the button (but still the finger on the screen) then the button never receive the “release” event.

Is this a bug?

Thanks for any info.

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124023[/import]

Hi again

I am still looking at ways to remove focus on a widget button. It seems to me that a widget button should lose focus when the finger is no longer on it. Right now it seems that if you keep your finger on the button and then move your finger away from the button (but still the finger on the screen) then the button never receive the “release” event.

Is this a bug?

Thanks for any info.

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124024[/import]

I wrote an article/tutorial called Better Buttons in Corona SDK that may answer your question. You can see the video here:

http://gamedevnation.com/gdn-membership/better-buttons-in-corona-sdk/

Well, you could see it but it’s only available for GDN members…

…but since membership is free, don’t let that stop you. :wink:

Jay [import]uid: 9440 topic_id: 30771 reply_id: 124025[/import]

Hi again

I am still looking at ways to remove focus on a widget button. It seems to me that a widget button should lose focus when the finger is no longer on it. Right now it seems that if you keep your finger on the button and then move your finger away from the button (but still the finger on the screen) then the button never receive the “release” event.

Is this a bug?

Thanks for any info.

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124023[/import]

Hi again

I am still looking at ways to remove focus on a widget button. It seems to me that a widget button should lose focus when the finger is no longer on it. Right now it seems that if you keep your finger on the button and then move your finger away from the button (but still the finger on the screen) then the button never receive the “release” event.

Is this a bug?

Thanks for any info.

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124024[/import]

I wrote an article/tutorial called Better Buttons in Corona SDK that may answer your question. You can see the video here:

http://gamedevnation.com/gdn-membership/better-buttons-in-corona-sdk/

Well, you could see it but it’s only available for GDN members…

…but since membership is free, don’t let that stop you. :wink:

Jay [import]uid: 9440 topic_id: 30771 reply_id: 124025[/import]

Sorry Jay for the delay. I am a member to your wonderful blog. I saw that article a long time ago and forgot about it. Thank you for remind me about it. That should work. I was just hoping to keep using the widget button (since I am using many buttons on my app) but it may not possible. Your solution maybe the only way since I am not sure how to make the widget button lose focus in case a user do not remove his/her finger.

Thanks a lot Jay!

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124971[/import]

Sorry Jay for the delay. I am a member to your wonderful blog. I saw that article a long time ago and forgot about it. Thank you for remind me about it. That should work. I was just hoping to keep using the widget button (since I am using many buttons on my app) but it may not possible. Your solution maybe the only way since I am not sure how to make the widget button lose focus in case a user do not remove his/her finger.

Thanks a lot Jay!

Mo [import]uid: 100814 topic_id: 30771 reply_id: 124971[/import]