cocos2dx實現遮罩的兩種方法
1.clipnode
auto clip = CCClippingNode::create();
auto stencil = CCSprite::create("mask.png");
clip->setStencil(stencil);
clip->setInverted(false);
clip->setAlphaThreshold(0);
clip->addChild(CCSprite::create("head.png"));
2.blendFunc
auto mask = CCSprite::create("mask.png");
auto sizeOfImg = mask->getContentSize();
CCPoint centreOfImg = ccpMidpoint(CCPointZero, sizeOfImg);
mask->setPosition(centreOfImg);
CCRenderTexture * pRt = CCRenderTexture::create(sizeOfImg.width,sizeOfImg.height, kTexture2DPixelFormat_RGBA8888);
auto head = CCSprite::create("head.png")
head->setPosition(centreOfImg);
ccBlendFunc maskBlend = {GL_ONE, GL_ZERO};
ccBlendFunc flowerBlend = {GL_DST_ALPHA,GL_ZERO};
mask->setBlendFunc(maskBlend);
head->setBlendFunc(flowerBlend);
pRt->begin();
mask->visit();
head->visit();
pRt->end();