I have for example three buttons, and I will check if there is a click outside the buttons, how can I solve this?
Jump to content
If you have an invisible object, you can use its .isHitTestable member and set it to true and it will react to touch/tap events.
Are you making your own buttons or using widget.newButton(). If you're making your own, remember touch events have multiple phases (touch began, touch ended, potential touch moved), touch and tap are different events, and if you're handling your own, you need to return true at the end of the handler function to make sure the touch doesn't propagate their way through the display hierarchy.
If you want to ensure that touches generated by an object are retained by that object until the touch is released, you can try using a touch listener like this:
local function touch(e) if (e.phase == "began") then e.target.hasFocus = true display.currentStage:setFocus(e.target) e.target.touchjoint = physics.newJoint( "touch", e.target, e.x, e.y ) -- physics API return true elseif (e.target.hasFocus) then e.target.touchjoint:setTarget( e.x, e.y ) -- physics API if (e.phase == "moved") then else e.target.hasFocus = nil display.currentStage:setFocus(nil) e.target.touchjoint:removeSelf() -- physics API e.target.touchjoint = nil -- physics API end return true end return false end
Remove the physics API lines as needed.