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 ?
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
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
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
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