1. 程式人生 > >lua 中實現遮罩層和遮蔽層

lua 中實現遮罩層和遮蔽層

    --遮罩層
    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,所以同樣可以實現觸控式螢幕蔽。
這裡只是為了看起來更清晰。