i want to show a pop up of game exit on keybackclicked() event, the issue is pop up is thrown but back layer still takes the touch
i tried using this~~>setTouchEnabled; but failed, can anyone help me with this ?
Below is the code
void MenuLayer::keyBackClicked
{
this~~>setTouchEnabled(false);
Make sure the top layer has highest priority (priority for touch handling is the highest negative value gets touches first), and swallows touches. If the priority of touches is correct you shouldn’t need to do any extra work.
This is a standard use of a cover layer. Here is my implementation:
#ifndef __COVER_LAYER_H__
#define __COVER_LAYER_H__
/*
The cover layer is basically a layer that stops touches from going to its parent.
Right now this is hackish. If it doesn't work I can recursively turn off touches
for all parents... (think about that...)
The cover layer also adds a black tint to whatever it's covering to give it a
"disabled" modal look.
*/
#include "cocos2d.h"
#include "ui/CocosGUI.h"
class CoverLayer : public cocos2d::LayerColor
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
virtual bool onTouch(cocos2d::Touch*, cocos2d::Event*);
// implement the "static create()" method manually
CREATE_FUNC(CoverLayer);
protected:
bool _covered = true;
};
#endif // __COVER_LAYER_H__
Yeah since I’ve posted that two years ago, touch handling has been greatly simplified. It’s more intuitive; things on top (z order) get touches first with default touch handling.
There wasn’t really a link to it but I’ve found someone describing how it was (2.x ish?) on stackoverflow. Maybe you could find the old docs for those versions.
Those were dark days: disabling layers and managing touch priorities (which were opposite of render order ).