cocos2dx3.16 notificationNode 无法屏蔽触摸

3.10的版本中使用NotificationNode 可以在它身上add 一个layout setSwallowTouches(true) 来屏蔽下层的touch响应。。同样的代码在更新2dx版本为3.16后 发现无法屏蔽下层的touch响应了。。怀疑是新版本的bug,求指导

设置了事件吞没,是在这个node收到事件后,这个事件不再向下传递。这种情况是不是 layout 就没收到触摸事件?

@elvis_cheng 给个简单重现 demo 吧。

local backLayer = ccui.Layout:create();
backLayer:setContentSize(cc.size(display.width, display.height))
backLayer:setBackGroundColorType(LAYOUT_COLOR_SOLID)
backLayer:setBackGroundColor(cc.c3b(255,255,255))
backLayer:setBackGroundColorOpacity(255)
backLayer:setPosition(cc.p(0,0))
display.getRunningScene():addChild(backLayer,0);
local button = ccui.Button:create("gui/button00230.png");
button:setPosition(cc.p(display.width / 3 * 2, display.height / 5));
display.getRunningScene():addChild(button,2);

button:addTouchEventListener(function (sender, eventType)
	if eventType == TOUCH_EVENT_ENDED then
		print("test")
	end)
		local layer = ccui.Layout:create()
		layer:setContentSize(cc.size(display.width, display.height))
		layer:setBackGroundColorType(LAYOUT_COLOR_SOLID)
		layer:setBackGroundColor(COLOR.BLACK)
		layer:setBackGroundColor(hex2c3b("000000"));
		layer:setBackGroundColorOpacity(127)
		layer:setTouchEnabled(true)
		layer:setSwallowTouches(true)
		layer:setAnchorPoint(cc.p(0.5, 0.5))
		layer:setPosition(cc.p(display.width/2,display.height/2));
		layer:setName("grayLayer")
		notificationNode:addChild(layer)

前面还需要设置下 notificationNode @minggo

notificationNode 不是在场景树里面的,你怎么让notificationNode里面的layout劫持touch事件呢?没法劫持啊。

一个思路是,自己定义个继承于Node的类,通过EventDispather::addEventListenerWithFixedPriority的方式去注册touch事件,然后去swallow。

好吧。之所以这么写。是因为之前版本行得通。那我用这个方法来做做看

不可能啊,之前版本是指?2.x?
至少3.x中,notificationnode中的如果加menuItem等是无法响应的。

https://github.com/cocos2d/cocos2d-x/pull/11275

这个PR有比较hack的做法,但是我们并不太推荐。

3.10版本。我的代码是3.10 可以使用的。。。新项目是移植到3.16上

这块代码应该一直没啥变化才是。

我也是这么觉得。也没发现太多的变化。。所以很疑惑