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


#1

Hie,

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


#2

Hi,

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.

Huabin


#3

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.


#4

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: http://www.cocos2d-x.org/forums/19/topics/42588. 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.setTouchMode(cc.TOUCH_ONE_BY_ONE);
    this._isTouchEnabled = true;

*refer to source codes if in doubt


#5

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