cocos2dx 3.6 How to Mask sprite in circle

You’r welcome!

Just in case there is some confusion about the position independence, regardless of it’s children state. I just wanted to point out, that you can position the clipping node, the stencil and the clipped node independently.

If you set the position of the clipping node to the center, the children (stencil and the sprite) of course have a standard relative position of (0 ,0) to the clipping node. So this will have the same result, as it is not needed to set both the stencil and the sprite to the center, but only the clipping node.

auto stencil = DrawNode::create();
stencil->drawSolidCircle(Vec2(0.0f, 0.0f), 50.0f, 0.0f, 32.0f, Color4F::GREEN);

// create the clipping node and set the stencil 
auto clipper = ClippingNode::create();
clipper->setStencil(stencil);
clipper->setPosition(center);

// create the sprite, which should be clipped
auto sprite = Sprite::create();
sprite->setSpriteFrame("mysprite.png");

// add the sprite to the clipping node, so it can be clipped
clipper->addChild(sprite);

// add the clipping node to the main node
addChild(clipper);