Why doesn`t Cosos2d ClippingNode work properly?

358 Views Asked by At

I try to use ClippingNode for my Cocos2d project, but due to some unknown reason it doesn`t work the proper way neither on Iphone, nor Android. Here is the code being used. The stencil is Label with string "7". Are there any mistakes or is it simply a Cocos2d problem?

            auto colors = Sprite::create("colors.png");
            colors->setContentSize(Size(nodeSize.width * 1.25, nodeSize.height * 1.25));
            colors->setPosition(recordNumLbl->getPosition());
            colors->setName("recordNum");

            auto cropNode = ClippingNode::create(recordNumLbl);
            cropNode->setGlobalZOrder(11);
            cropNode->setName("cropNode");
            cropNode->addChild(colors);
            this->addChild(cropNode);

You can see the result I get on the first image, and what I try to get on the second one. Any help is highly appreciated!

https://i.stack.imgur.com/fZ9LX.png https://i.stack.imgur.com/xH1hp.png

1

There are 1 best solutions below

0
rh101 On BEST ANSWER

The global Z value needs to be exactly the same for any children of a clipping node. So, for the example you posted, you would need to set this:

colors->setGlobalZOrder(11);

Also, make sure the stencil you use (recordNumLbl?) is also set to a global Z of 11.