Size size = Director::getInstance()->getVisibleSize();
ClippingNode* clippingNode = ClippingNode::create();
Sprite* line3 = Sprite::createWithSpriteFrameName(“rope-1.png”);
LayerColor* layer = LayerColor::create(Color4B::WHITE);
layer->setPosition(size.width / 2 - 100, size.height / 2 - 100);
layer->setContentSize(Size(200, 200));
line3->setPosition(layer->getContentSize().width / 2, layer->getContentSize().height / 2);
layer->addChild(line3);
clippingNode->addChild(layer);
clippingNode->setInverted(true);
line3->runAction(RepeatForever::create(
Sequence::create(
CCCallFunc::create(()->void{
line3->setPositionX(-line3->getContentSize().width / 2.0f);
}),
MoveBy::create(1.0f, Vec2(200.0f + line3->getContentSize().width, 0.0f)),
NULL)
));
DrawNode* node = DrawNode::create();
Vec2 vecs] = {
Vec2(size.width / 2 - 50, size.height / 2 - 50),
Vec2(size.width / 2 + 50, size.height / 2 - 50),
Vec2(size.width / 2 + 50, size.height / 2 + 50),
Vec2(size.width / 2 - 50, size.height / 2 + 50)
};
node->drawPolygon(vecs, 4, Color4F(1, 1, 1, 1), 1, Color4F(1, 1, 1, 1));
clippingNode->setStencil(node);
clippingNode->setPosition(this->getContentSize().width / 2.0f, this->getContentSize().height / 2);
this->addChild(clippingNode);
最后得到的结果
什么版本的?
我用的是COCOS2DX 3.4
我今天用3.2的版本上,结果正确显示了,在3.4上就出问题了
这个功能我这边试了下,没感觉问题。可否提供个重现Demo
初步怀疑是升级到3.4后没设置glContextAttrs导致, 在创建渲染窗口之前调用如下代码试试
GLContextAttrs glContextAttrs = { 8, 8, 8, 8, 24, 8 }; // make clipping ok
GLView::setGLContextAttrs(glContextAttrs);
6楼 大大 厉害!






有一个sprite,我在renderTexture里面渲染,然后把这个renderTexture再替换到sprite的txture。
然后重复多次上诉操作,这个sprite的颜色会变得越来越淡。
这个怎么解决呢
我用的 3.5 lua 版本, 用了 ClippingNode 也是出现白底的问题, 6楼说的那个我检查了也是有设置的
不要在windows上纠结这些问题 cocos可能根本不管这些windows模拟器
testbird测试有部分手机显示问题啊



我也遇到同样问题,cocos2dx3.8 在ios 和安卓上都出现同样问题 设置gl属性那个也设置了 没有用
亲测,cocos2dx 3.4 lua,在windows vs上使用clippingNode有一个白色的背景,但是在mac的模拟器上显示就是一切正常的