I think maybe you should put them in one layer. Setting the ZOrder of the menu can make it display on the top.
If we have to use two layers, we can put the second layer (which contains the menu) on(that means, cover) the first layer and modify it like this: (my layer’s name is MenuLayer)
// in the .h file
protected:
bool _menuTouched; // it's true if the menu is touched
CCMenu _menu;
// use "Menu _menu;" if using cocos2d-x 3.0 or later
// in the .cpp file
bool MenuLayer::init()
{
if (!CCLayer::init()) return false;
setTouchEnabled(true);
_menu = CCMenu::create();
// add some items to the menu
// ...
_menuTouched = false;
return true;
}
void MenuLayer::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
}
bool MenuLayer::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{
_menuTouched = _menu->ccTouchBegan(touch, event);
return _menuTouched;
// if the menu is touched, stop click propagation
// otherwise the click will be sent to the next layer (map layer).
}
void MenuLayer::ccTouchMoved(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{
if (_menuTouched)
_menu->ccTouchMoved(touch, event);
}
void MenuLayer::ccTouchEnded(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{
if (_menuTouched)
{
_menu->ccTouchEnded(touch, event);
_menuTouched = false;
}
}
void MenuLayer::ccTouchCancelled(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
{
if (_menuTouched)
{
_menu->ccTouchEnded(touch, event);
_menuTouched = false;
}
}
But please notice that if you chose this way, the MenuLayer can only contain one menu and no other things.
I am glad to help, but I don’t know much about js. I’m sorry about that.
You can find information about this at Google and at this website.
I hope you can find what you need. Good luck!
P.S. If you find that please tell me, I want to learn it, too.
P.P.S. Sorry, I didn’t see it’s in HTML5 section
Is there anybody can help to solve this problem? I’m also new with cocos2d-html5 too and can’t find anything to stop propagation in this situation. Please help me!
For touch propagation, you can see the answer of this post: http://cocos2d-x.org/forums/19/topics/42588
I have made a test case for illustrate how to prevent propagation of touch event.