New issue
 Projects > js > Issues > Bug #4035

Fix Touch Propagation on MenuItem

Bug #4035 [New]
ZippoLag 2014-02-13 15:33

I have a layer, let's call it "messageLayer", above my "gameLayer", that swallowes (stops the propagation of) touches correctly as was discovered in this thread:

In that messageLayer I've placed a Menu. When one of the MenuItems is activated, a callback is excecuted and the layer automatically dissapears. That's all right.

But for some reason, the gameLayer registers a onMouseUp event, while it should have been swallowed when the MenuItem was activated.

Upon inspection of the classes, I've discovered that the actual touch/mouse interaction is done in "CCMenu.js", where both onMouseUp and onTouchEnded trigger the following:
<pre> onTouchEnded:function (touch, e) {
if(this._state !== cc.MENU_STATE_TRACKING_TOUCH){
cc.log("cc.Menu.onTouchEnded(): invalid state");
if (this._selectedItem) {
this._state = cc.MENU_STATE_WAITING;

Now, I have tried to add a "return true;" to that method, but it's not achieving the desired effect (the click is still propagating).

For now, in my game, I've settled for using a flag that I set to "true" when I show my messageLayer and, in my gameLayer's onMouseUp event do nothing but setting it to "false" if it was true, therefore discarding the propagated click, but this could be quite troublesome in the future.

Atom PDF

Start date:2014-02-13
Due date:
% Done:


Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.