cocos2dx - lua 中实现遮罩层和屏蔽层

发表于2015-12-02
评论0 2k浏览
  1.  --遮罩层  
  2.     local maskLayer = CCLayerColor:create(ccc4(0, 0, 0, 120), visibleSize.width, visibleSize.height);  
  3.     self:addChild(maskLayer)  
  4.       
  5.     --触摸屏蔽层  
  6.     local touchLayer = CCLayer:create();  
  7.     touchLayer:setContentSize(CCSize(visibleSize.width, visibleSize.height))  
  8.       
  9.     local function touchLayerCallFunc(eventType, x, y)  
  10.         --LuaLog("======000========", eventType)  
  11.         --LuaLog("======111========", x)  
  12.         --LuaLog("======222========", y)  
  13.     //在began触摸时,返回true,消息将被拦截,这样就实现了屏蔽层  
  14.         if eventType == "began" then  
  15.             return true  
  16.         end  
  17.     end  
  18.       
  19.     --这个函数的使用我在这篇博客中有说明(http://blog.csdn.net/tianxiawuzhei/article/details/46011101)  
  20.     touchLayer:registerScriptTouchHandler(touchLayerCallFunc, false, newPriority, true)  
  21.     touchLayer:setTouchEnabled(true)  
  22.     maskLayer:addChild(touchLayer)  
  23. 总结:  
  24. 其实上面两个层可以和为一个层,因为CCLayerColor本身就是继承自CCLayer,所以同样可以实现触摸屏蔽。  
  25. 这里只是为了看起来更清晰。  

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引