How to block touch events?

How to block touch events?

Hi how can i block touch events from other nodes?
basically i have lots of menus (start menu,option menu, building menu, etc menu) with labels and buttons in them…
some of them are behaving like pop up menus that may overlap other menus, thats where my problem occurs…
when menu A is on top of menu B… the menu B can still receive touch events when i touch menu A…

my scene node hierarchy :

    - UIManager
        - build menu
        - troops menu
        - Shop menu
        - Allies menu
        - etc menu

is it possible to intercept events without using cc.eventManager?
because i want it in a easier way rather than looping through all of them and stopping the bubbling of event object

I don’t understand why it can’t, if menu A is the sibling node of menu B, and if menu A has registered touch event, then it will block event from dispatching to menu B. The event bubbling only dispatch to the target’s parents node. So basically when child node of build menu receives touch event, it will bubbling to build menu then to UIManager, then to Canvas.

Are you register event to UIManager to detect something and you are receiving it ? Can you be more specific about the event trace you are experiencing ?

@pandamicro im am just using a simple cc.Button… as far as i know it alread have a listener on it right?..
for example menu A is on top of menu B.
when i click on an area in menu A(even if there is no button where i clicked), and menu B has a button on that area… the button of menu B under that area still receives the event… how can i block that? hehe thanks…

Oh, I see

In your menus, only buttons listen to the touch events, so if you click on an empty area of MenuA, you will receive the touch event in MenuB’s button. What you need is to register the touch event on your Menu, then it will swallow all touch events.

I would run it like game state,

in my loop i have a switch case for run and pause in game or menu and stuff


switch (GAME_STATE) {

case RUN:

case MENU:
//Pause game do menu stuff

case PAUSE:
// do noting

can you not do something

switch (MENU_LEVLE) {

case MENU_A:
//level A menu only test for the menu buttons a

case MENU_B:
////level B menu only test for the menu buttons b


someone may reply just to block out sub levels of menus but this is how i sort of see it as you have to stop and pause game in background in menus anyway.
hope this may you helps.

@RazerJack thank you for your suggestion… but thats one style of programming…
i am using entity component system approach and fsm can be fused with ecs but for now its not needed hehe, but you gave me an idea on my next step thanks man… :innocent:

I’m struggling with same problem :frowning:
If you solve it, could you share the solution?

you can use the component UI->Block Input Events in the top node. so for example node A and its children contain a menu (A). Now, you want a second menu(B), which is hidden behind menu(A), not to receive touch events which are being registered by menu(A) then put the component in node A.
hope this helps.