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]