Blocking events.

Hi - I’m working on a Composer type set of classes. I have an overlay as with Composer, that appears over the top of a current scene. To make it modal I need to disable tap and touch events on the view below, so that (for example) the overlay cannot be re-opened.

Is there a better way of doing this than putting a transparent rectangle between the two of them and trapping tap/touch events on it ?

the isModal flag handles this for Composer and Storyboard.

Sorry wasn’t clear ; I’m writing something that does what Composer does ; I found wrapping it in classes to be a bit chaotic. So I’m basically using the same ideas, including modal overlays.

Seems weird to re-invent the wheel, but you could use the setFocus API.

There’s not a lot of it, and the current design is very difficult to create a clean Adaptor for. The main problem is not the scenes per se but lack of control of the Scene Manager. The wrapper is about 1/2 of the size of the rewrite (discounting the transition definitions) :slight_smile:

The reason is I can write things like this:

AutoClass = sm.DelayScene:new() function AutoClass:create()         self:insert(display.newText("And now ...",160,320,native.systemFont,24)) end function AutoClass:nextScene() return "thirdscene" end function AutoClass:sceneDelay() return 2500 end

This is a scene class (instance as well because of prototyping) which displays the “and now” text for 2500 and transits to the scene ‘thirdscene’ automatically. I will almost certainly move the bottom two lines into the constructor. Still have access to the events and so on, if required. It’s a template class.

Is there a better way of doing this than putting a transparent rectangle between the two of them and trapping tap/touch events on it ?

Probably not - that’s likely the “best” solution (and is what director/storyboard/composer do). If .isHitTestable worked “both ways” (which it doesn’t) then you could sweep through your “lower” scene and disable everything, but you can’t.
You could (potentially) create a standard mechanism for registering listeners in your scenes, so that they could be automatically removed by a popup (tricky tho if your popup returns to SAME scene, then need to restore listeners again)
touch-blocking rect is simpler :smiley:

the isModal flag handles this for Composer and Storyboard.

Sorry wasn’t clear ; I’m writing something that does what Composer does ; I found wrapping it in classes to be a bit chaotic. So I’m basically using the same ideas, including modal overlays.

Seems weird to re-invent the wheel, but you could use the setFocus API.

There’s not a lot of it, and the current design is very difficult to create a clean Adaptor for. The main problem is not the scenes per se but lack of control of the Scene Manager. The wrapper is about 1/2 of the size of the rewrite (discounting the transition definitions) :slight_smile:

The reason is I can write things like this:

AutoClass = sm.DelayScene:new() function AutoClass:create()         self:insert(display.newText("And now ...",160,320,native.systemFont,24)) end function AutoClass:nextScene() return "thirdscene" end function AutoClass:sceneDelay() return 2500 end

This is a scene class (instance as well because of prototyping) which displays the “and now” text for 2500 and transits to the scene ‘thirdscene’ automatically. I will almost certainly move the bottom two lines into the constructor. Still have access to the events and so on, if required. It’s a template class.

Is there a better way of doing this than putting a transparent rectangle between the two of them and trapping tap/touch events on it ?

Probably not - that’s likely the “best” solution (and is what director/storyboard/composer do). If .isHitTestable worked “both ways” (which it doesn’t) then you could sweep through your “lower” scene and disable everything, but you can’t.
You could (potentially) create a standard mechanism for registering listeners in your scenes, so that they could be automatically removed by a popup (tricky tho if your popup returns to SAME scene, then need to restore listeners again)
touch-blocking rect is simpler :smiley: