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

前端之家收集整理的这篇文章主要介绍了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

猜你在找的Cocos2d-x相关文章