DrawNode遮罩

话不多说

spriteNode = sprite;

spriteNode->setAnchorPoint(Vec2(0.5, 0.5));


clippeNode = ClippingNode::create();
clippeNode->setInverted(true);//设置底板可见(显示裁剪区域)
clippeNode->setAlphaThreshold(255);//设置绘制模板的alpha值


this->addChild(clippeNode, 10);
LayerColor *layerColor = LayerColor::create(Color4B(0, 0, 0, 0));
clippeNode->addChild(spriteNode);
clippeNode->addChild(layerColor);


// DrawNode *pDrawNode = DrawNode::create();
// Color4F drawColor = { 1, 1, 0, 0 };
// Vec2 rect[4] = {
// Vec2(-numRadius, 0),
// Vec2(-numRadius, numRadius*2),
// Vec2(numRadius, numRadius*2),
// Vec2(numRadius, 0)
// };
// pDrawNode->drawPolygon(rect, 4, drawColor, 0, drawColor);
// pDrawNode->setPosition(offset);
// pDrawNode->setAnchorPoint(Vec2(0.5, 0));
// pDrawNode->setRotation(originAngle);
Sprite *pDrawNode = Sprite::create("4.png");
pDrawNode->setAnchorPoint(Vec2(0.5, 0));
pDrawNode->setPosition(offset);
pDrawNode->setRotation(originAngle);
//抗锯齿  
pDrawNode->getTexture()->setAntiAliasTexParameters();
//pDrawNode->getTexture()->setAliasTexParameters();//不抗锯齿

clippeNode->setStencil(pDrawNode);

这部分代码其实在做一个写一个环形进度条的,不过后来一想这部分代码的实现可以做的事好多,比如说消除类的游戏,消除了部分元素后补充的元素从上方掉下来,只是在消除区域才能看到,我当时就在想怎么做到的,后来写了这个之后觉得可能就是通过上面这种形式实现的,rect你自己画一个矩形然后只显示矩形以内的东西,这样就可以实现了,

LayerColor *colorLayer = LayerColor::create(Color4B(0, 0, 0, 0));
colorLayer->setPosition(Vec2(-middleStar_x + 4.5 * starPriteSize.width, -middleStar_y + 4.5 * starPriteSize.height));
node = ClippingNode::create();
node->setPosition(Vec2(middleStar_x - 4.5 * starPriteSize.width, middleStar_y - 4.5 * starPriteSize.height));
this->addChild(node);
node->setInverted(false);
node->setAlphaThreshold(255);
node->addChild(colorLayer, 0);


DrawNode* pDrawNode = DrawNode::create();
Color4F drawColor = { 0, 0, 0, 0 };
Vec2 rect[4] = {
Vec2(0, 0),
Vec2(9 * starPriteSize.width, 0),
Vec2(9 * starPriteSize.width,  9 * starPriteSize.height),
Vec2(0, 9 * starPriteSize.height)
};
pDrawNode->drawPolygon(rect, 4, drawColor, 0, drawColor);
pDrawNode->setPosition(Vec2::ZERO);
node->setStencil(pDrawNode);


然后只需要把元素添加在colorLayer上就可以了,希望对博友有帮助。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奥特曼VS怪兽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值