Scale9Sprite作遮罩时,透明的地方没有裁剪
如附件显示的效果。
测试代码:
local sprite
local layerColor
local clip
local alphaThreshold = 0 -- 取值0~0.9都是一样的效果
-- 灰色背景
layerColor = cc.LayerColor:create(cc.c4b(151,151,151,255), 854, 480)
self:addChild(layerColor, 9)
----用Sprite裁减
-- 底
layerColor = cc.LayerColor:create(cc.c4b(0,0,255,255), 100, 100)
layerColor:ignoreAnchorPointForPosition(false)
layerColor:setAnchorPoint(0.5,0.5)
layerColor:setPosition(100, 300)
self:addChild(layerColor, 10)
-- 遮罩
sprite = cc.Sprite:createWithSpriteFrameName("button_start_02.png")
sprite:setPosition(300, 300)
self:addChild(sprite, 10)
sprite = cc.Sprite:createWithSpriteFrameName("button_start_02.png")
clip = cc.ClippingNode:create(sprite)
clip:setAnchorPoint(cc.p(0.5,0.5))
clip:setPosition(500, 300)
clip:setAlphaThreshold(alphaThreshold)
-- 被裁减的蓝色背景
layerColor = cc.LayerColor:create(cc.c4b(0,0,255,255), 100, 100)
layerColor:ignoreAnchorPointForPosition(false)
layerColor:setAnchorPoint(0.5,0.5)
clip:addChild(layerColor)
self:addChild(clip, 10)
----用Scale9Sprite裁减
-- 底
layerColor = cc.LayerColor:create(cc.c4b(0,255,0,255), 100, 100)
layerColor:ignoreAnchorPointForPosition(false)
layerColor:setAnchorPoint(0.5,0.5)
layerColor:setPosition(100, 100)
self:addChild(layerColor, 10)
-- 遮罩
sprite = cc.Scale9Sprite:createWithSpriteFrameName("button_start_02.png", cc.rect(38,40,1,1))
sprite:setContentSize(cc.size(80, 100))
sprite:setPosition(300, 100)
self:addChild(sprite, 10)
sprite = cc.Scale9Sprite:createWithSpriteFrameName("button_start_02.png", cc.rect(38,40,1,1))
sprite:setContentSize(cc.size(80, 100))
clip = cc.ClippingNode:create(sprite)
clip:setAnchorPoint(cc.p(0.5,0.5))
clip:setPosition(500, 100)
clip:setAlphaThreshold(alphaThreshold)
-- 被裁减的绿色背景
layerColor = cc.LayerColor:create(cc.c4b(0,255,0,255), 100, 100)
layerColor:ignoreAnchorPointForPosition(false)
layerColor:setAnchorPoint(0.5,0.5)
clip:addChild(layerColor)
self:addChild(clip, 10)