Skip to content

Instantly share code, notes, and snippets.

@litefeel
Last active August 29, 2015 14:23
Show Gist options
  • Save litefeel/c0c92d7daf6d56dca914 to your computer and use it in GitHub Desktop.
Save litefeel/c0c92d7daf6d56dca914 to your computer and use it in GitHub Desktop.
masker by blendFunc
// 使用混合做遮罩
CCSize size = m_pMask->getContentSize();
CCRenderTexture *renderTexture = CCRenderTexture::create(size.width, size.height);
// 设置默认颜色
renderTexture->setClearColor(ccc4f(0, 0, 0, 0));
// 设置清除颜色标记,否则autoDraw时不能清除颜色
renderTexture->setClearFlags(GL_COLOR_BUFFER_BIT);
ccBlendFunc func = { GL_ZERO, GL_SRC_ALPHA };
m_pMask->setBlendFunc(func);
renderTexture->addChild(firstSp);
renderTexture->addChild(secendSp);
renderTexture->addChild(m_pMask);
// 如果被遮罩为非静态的,需要设置autoDraw
renderTexture->setAutoDraw(true);
renderTexture->setPosition(ccp(pSpNormal->getContentSize().width/2, pSpNormal->getContentSize().height/2));
pSpNormal->addChild(renderTexture);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment