制作一个类似遮罩的效果,然后抠出不该被遮挡的部分
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//背景图
CCSprite* sp = CCSprite::create("PIC_BJ_CJ4.png");
sp->setPosition(ccp(640,400));
addChild(sp);
//创建剪裁节点
CCClippingNode* pClip = CCClippingNode::create();
//设置是否反向,将决定画出来的圆是透明的还是黑色的
pClip->setInverted(true);
addChild(pClip);
//图层添加到剪裁节点上
CCLayerColor* pLayer = CCLayerColor::create(ccc4(0,110));
pClip->addChild(pLayer);pLayer->setAnchorPoint(ccp(0.5,0.5));
//制作一个圆的数据
ccColor4F color = {0,0};//R G B 透明度
float radius = 55.0f;//半径
const int nCount = 200; //设置顶点数, 设圆有200个顶点
const float angel = 2.0f * (float)M_PI/nCount; //两个顶点与中心的夹角(弧度)
CCPoint circle[nCount];
for (int i=0; i<nCount; i++)
{
float radian = i * angel;
circle[i] = ccp(radius * cosf(radian),radius * sinf(radian));
}
//制作一个四边形的数据
const int Count = 4;
static CCPoint pos[Count]; //多变形各点坐标 相对于postion的偏移
CCPoint center(visibleSize.width/2,visibleSize.height/2);
pos[0] = ccp(540,500);
pos[1] = ccp(center.x + 100,center.y + 100);
pos[2] = ccp(center.x + 100,center.y - 100);
pos[3] = ccp(center.x - 100,center.y - 100);
//绘制四边形
pStencil = CCDrawNode::create();
//pStencil->drawPolygon(circle,nCount,color,color); //绘制那个圆
//pStencil->setPosition(visibleSize.width/2,visibleSize.height/2); //数组circle的坐标是相对positon的偏移
pStencil->drawPolygon(pos,Count,color); //绘制那个四边形
pClip->setStencil(pStencil); //抠出这个多边形
以上整个代码在init中就好