Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to disable all touch events ?
Started by JTPenn Sep 02 2019 07:48 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

JTPenn

[GLOBAL: userInfoPane.html]
JTPenn
  • Contributor

  • 101 posts
  • Corona SDK

I have a panel which appears on top of UI elements that inform the user of loading in progress, the user can interact with the UI elements in the background, I know that a simple boolean variable and a check at each touch event would work, but is there a another way ? for example to intercept all touch events and decide if it should continue ?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 892 posts
  • Corona SDK

I usually just do the following:

local function block(e)
    return true
end

local sensor = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight )
sensor.isVisible = false
sensor.isHitTestable = true
sensor:addEventListener( "touch", block )
sensor:addEventListener( "tap", block )

When I need to block something, I just set "isHitTestable" to true, otherwise false.


  • AlanPlantPot likes this

[TOPIC: post.html]
#3

JTPenn

[GLOBAL: userInfoPane.html]
JTPenn
  • Contributor

  • 101 posts
  • Corona SDK

I usually just do the following:

local function block(e)
    return true
end

local sensor = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight )
sensor.isVisible = false
sensor.isHitTestable = true
sensor:addEventListener( "touch", block )
sensor:addEventListener( "tap", block )

When I need to block something, I just set "isHitTestable" to true, otherwise false.

Yes I understand this technique problem is I have many ui elements on the screen with many touch events, I don't want to set a property for each element or put a condition in each touch event.
I want to intercept touch events and decide wether they should be called or cancelled



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 892 posts
  • Corona SDK

You seem to have misunderstood my example.

 

That rectangle is invisible and it covers the entire screen. If you set it in the topmost group, then it will block all taps and touches to all other display objects.

 

If you want to block all taps and touches, all you'd need to type is "sensor.isHitTestable = true" and no other event can trigger. This happens because of the return true at the end of the block function, i.e. the sensor takes the touch and prevents taps/touches from propagating. When you no longer want to block them, just set "sensor.isHitTestable = false".



[TOPIC: post.html]
#5

JTPenn

[GLOBAL: userInfoPane.html]
JTPenn
  • Contributor

  • 101 posts
  • Corona SDK

You seem to have misunderstood my example.

 

That rectangle is invisible and it covers the entire screen. If you set it in the topmost group, then it will block all taps and touches to all other display objects.

 

If you want to block all taps and touches, all you'd need to type is "sensor.isHitTestable = true" and no other event can trigger. This happens because of the return true at the end of the block function, i.e. the sensor takes the touch and prevents taps/touches from propagating. When you no longer want to block them, just set "sensor.isHitTestable = false".

Aha, sorry now I understand.

Yes that's exactly what I wanted, Thanks very much <3




[topic_controls]
[/topic_controls]