cocos2d-x3.x屏蔽触摸遮罩层屏蔽按钮

cocos2d-x3.x之后触摸方法有所改变,要屏蔽掉某一层的触摸事件其实很简单,首先touchbegan一定要返回true,其次给监听事件设置吞噬触摸为true,最后注册触摸层级一定要小于0,目前不能设置层级为0了,切记

转载请注明地址:白白http://blog.csdn.net/u010229677

<span style="font-size:18px;">auto touchListener=EventListenerTouchOneByOne::create();
	touchListener->onTouchBegan=[=](Touch *touch,Event *event)
	{
		touchListener->setSwallowTouches(true);
		return true;
	};
	_eventDispatcher->addEventListenerWithFixedPriority(touchListener,-5); //也可以把-5换成this</span>


或者这么写,其实都是一个道理

<span style="font-size:18px;">	auto callBack = [](Touch*, Event*)
	{
		return true;
	};
	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = callBack;
	listener->setSwallowTouches(true);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);</span>


你可能感兴趣的:(按钮,cocos2d-x,屏蔽触摸,3.)