set priority to touch events for multiple layers in cocos-html5?



I have my main game layer and above that i have my game exit layer where once user clicks exit activate the layer by using setVisible(true).
The problem is on the game layer when user randomly clicks on the location occupied by the exit layer the touch is sensing and action to be performed by the exit layer is there a way to set priority to set touches to the main game layer so that tha the exit layer touches wont effect my game layer?



I believe you used setTouchPriority for your layers. Though the priority test doesn’t check the visibility of your layer, so you should do the test in your touch event handlers, the logic is like the following:

  1. When the handler receives an event, check the visibility of the current layer
  2. I it’s not visible return false directly

Then I think it will ignore the exit layer when it’s not visible.



Iam sorry that have not used the setTouchPriority function in my layers.I could not find the function and how to use it effectively.

is there any method which checks for the visibility of the layer which returns bool value for visibility?

Can you please give me any example code for the setTouchPriority method and its use?

I would be grateful to you.


you mean deactivate your post using setVisible (false)? I am unclear of the question you have posted.

In any case, look to the forum post: I’ve been asking questions pertaining to touch swallowing and propogation and Huabin was really helpful. (still is)

  1. with the HTML5 api , I believe you can getTouchPriority as well as Set it. Visibility not too sure
  2. For every new layer that you’ve created and you wish to have that layer swallow any touch so that it does not permeate through to the layer beneath it (i presume it is your main game layer that is residing below the “exit” layer), add the touch events to the “swallowing” layer - refer to link above for touch functions - and set the “swallowing” (or “exit” in your context) layer with the following in the constructor:
    this._isTouchEnabled = true;

*refer to source codes if in doubt


Thanks a lot kwok.It was very useful and thanks to huabin for quick reply.