--遮罩层
local maskLayer = CCLayerColor:create(ccc4(0, 0, 0, 120), visibleSize.width, visibleSize.height);
self:addChild(maskLayer)
--触摸屏蔽层
local touchLayer = CCLayer:create();
touchLayer:setContentSize(CCSize(visibleSize.width, visibleSize.height))
local function touchLayerCallFunc(eventType, x, y)
--LuaLog("======000========", eventType)
--LuaLog("======111========", x)
--LuaLog("======222========", y)
//在began触摸时,返回true,消息将被拦截,这样就实现了屏蔽层
if eventType == "began" then
return true
end
end
--这个函数的使用我在这篇博客中有说明(http://blog.csdn.net/tianxiawuzhei/article/details/46011101)
touchLayer:registerScriptTouchHandler(touchLayerCallFunc, false, newPriority, true)
touchLayer:setTouchEnabled(true)
maskLayer:addChild(touchLayer)
总结:
其实上面两个层可以和为一个层,因为CCLayerColor本身就是继承自CCLayer,所以同样可以实现触摸屏蔽。
这里只是为了看起来更清晰。
cocos2dx - lua 中实现遮罩层和屏蔽层
最新推荐文章于 2020-09-15 09:31:54 发布