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


self.imgFJ = cc.Sprite:create("#fj.png")
    self.imgFJ:setAnchorPoint(0,1)    
    self.imgFJ:setPosition(self.winSize.width*0.71,self.winSize.height*0.95)
    local imgX = self.imgFJ:getPositionX()
    local imgY = self.imgFJ:getPositionY()
    local size = self.imgFJ:getContentSize()

    -- local layer = cc.LayerColor:create({ r = 30,g = 30,b = 30,a = 180 },self.winSize.width,self.winSize.height)
    layer = cc.Layer:create()

    local function touchLayerCallFunc(eventType,x,y)
        if event == "began" then
            -- print("======000========"..eventType)  
            -- print("======111========"..x)  
            -- print("======222========"..y) 

            if x >= imgX and x <= imgX + size.width  and
                y <= imgY and y >= imgY - size.height   then    -- 点击在layer的imgFJ上时吞并触摸

                print("吞并触摸")
                return true
            end            
        end

        print("不吞并触摸")
        return false
    end

    layer:registerScriptTouchHandler(touchLayerCallFunc)
    layer:setTouchEnabled(true)
    layer:addChild(self.imgFJ)    
    self:addChild(layer)

遮罩层上高亮显示部分区域
-- 遮罩层上剪切高亮圆形
function TipsWindow:HighLightInColoerLayer(pos)
    -- 遮罩层上剪切高亮圆形,开始
    self.colorLayer:hide()

    self.node = cc.Node:create()
    self.clip = cc.ClippingNode:create(self.node)
    self.clip:setInverted(true)
    self.clip:setAlphaThreshold(0)
    self:addChild(self.clip)

    self.blackLayer = cc.LayerColor:create(cc.c4b(0,150),display.width,display.height)
    self.clip:addChild(self.blackLayer)

    local glNode  = cc.GLNode:create()
    glNode:setContentSize(cc.size(120,120))
    glNode:setAnchorPoint(cc.p(0.5,0.5))
    local function primitivesDraw()
        gl.linewidth(2)
        cc.DrawPrimitives.drawColor4B(0,1)
        cc.DrawPrimitives.drawSolidCircle(pos,70,50,1,1)
    end
    glNode:registerScriptDrawHandler(primitivesDraw)
    self.node:addChild(glNode)
    self.glNode = glNode
    -- 遮罩层上剪切高亮圆形,结束
end

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...