3.3用Scale9Sprite作遮罩的bug

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)

这个我测了下,应该是BUG:12::12:
你可以关注下这个
https://github.com/cocos2d/cocos2d-x/issues/9977

现在3.3 是这段代码

所以没办法不在真机测试

#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#else
// since glAlphaTest do not exists in OES, use a shader that writes
// pixel only if greater than an alpha threshold
GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
// set our alphaThreshold
program->use();
program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
// we need to recursively apply this shader to all the nodes in the stencil node
// FIXME: we should have a way to apply shader to all nodes without having to do this
setProgram(_stencil, program);

#endif

真机测试效果也是不行的。android、iphone都测试过

我把win32的去掉了,拿回公司,整个项目重新编辑,效果就出来了

当然我的不是Scale9Sprite

一开始我也怀疑是不是64位和32位的GL不同,所以遮罩效果没出来

现在我还卡在打包android,没测试出来

在我回这个帖子的时候,居然又把 android打包搞好了,遮罩效果也是有的

这边检查完发现,不是Bug,是因为位置不对:12::12:楼主再检查下自己代码里面的位置
:10::10::10::12::12::12::12::5::5::5:
https://github.com/cocos2d/cocos2d-x/issues/9977

你看我的问题截图,如果位置不对,那怎么能截出一个位置正确的矩形?
能看看你的代码吗?

https://github.com/cocos2d/cocos2d-x/issues/9977
就是这个issues里面的代码,当stencil1->setPosition(Vec2(300,50));改为stencil1->setPosition(Vec2(300,-50));就出现了

测试,有裁减,但是透明部分无效,下面效果切图

你最后解决了吗?alpha通道确实没起作用