Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Click outside an object
Started by andreaszdw Feb 06 2019 06:56 AM

- - - - -
7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

andreaszdw

[GLOBAL: userInfoPane.html]
andreaszdw
  • Observer

  • 6 posts
  • Corona SDK

I have for example three buttons, and I will check if there is a click outside the buttons, how can I solve this?

 

Best regards

 

Andreas



[TOPIC: post.html]
#2

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

What is the actual problem?



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,205 posts
  • Enterprise

You can put a touch/tap listener on your background.

 

Rob



[TOPIC: post.html]
#4

andreaszdw

[GLOBAL: userInfoPane.html]
andreaszdw
  • Observer

  • 6 posts
  • Corona SDK

Yeah, I tried this, with the background. The problem is, every tap on the background is not on the button. The second is, if I make an rect background and set the alpha to zero, no tap is propagated, or am I wrong?



[TOPIC: post.html]
#5

andreaszdw

[GLOBAL: userInfoPane.html]
andreaszdw
  • Observer

  • 6 posts
  • Corona SDK

I try this tomorrow again, my wife wants me to go shopping with her now....

 

So have fun, I will have fun too...... :o



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,205 posts
  • Enterprise

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.  



[TOPIC: post.html]
#7

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

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.



[TOPIC: post.html]
#8

andreaszdw

[GLOBAL: userInfoPane.html]
andreaszdw
  • Observer

  • 6 posts
  • Corona SDK

Thank you, that helped me much.




[topic_controls]
[/topic_controls]