In the production of a elimination game, there is a situation: blocks from the top of the drop down, before entering the layout, is not displayed, otherwise affect the visual experience. So, since this block has already been added to the render tree, how can you make it appear in one part and display it in another?
This is going to cover the mask. In Cocos2d-x, a clipping node clippingnode is provided to achieve a clipping effect, so the clipped part is equal to the mask. It may have been more effective, and I have not studied it very well, just used it to deal with the above problems. The official introduction to this category is:
Http://www.cocos2d-x.org/docs/manual/framework/native/v3/ClippingNode/zh
The following records the method of using Clippingnode to complete the mask feature.
1. Create a new Clippingnode, which inherits from node;
2. To set the crop template for Clippingnode, the clipping template is also a node, but it is not displayed, and its default location is the coordinates origin of the Clippingnode;
3. Add child nodes for Clippingnode.
Clippingnode's child nodes are displayed only within the range of the clipping template, otherwise they are clipped or masked. It can be understood that there is a large black cloth, the contents of the Clippingnode inside all covered up, at this time, to the big black cloth opened a shape of the hole, as long as the inside of the hole in the content, will be displayed. This hole is the template.
The specific code is as follows:
//Window SizeAuto winsize = Director::getinstance ()getwinsize (); //Create a cropping nodeAuto Clipper =clippingnode::create (); Clipper->setposition (Winsize.width/2, Winsize.height/2); AddChild (clipper); //set a crop template that will not be drawn, just to mask theAuto stencil = Sprite::create ("Helloworld.png"); Clipper-Setstencil (stencil); //Add a crop node that does not appear in the Crop template rangeAuto Test_sprite = Sprite::create ("Powered.png"); Test_sprite->setposition ( -, -); Clipper->addchild (Test_sprite);
Display effect:
can see:
1. The crop template is not displayed, and the red box here is drawn separately to indicate the extent of the clipping template.
The child nodes of 2.ClippingNode are not rendered completely, only content that is inside the clip template will be rendered.
Mask Sprites with Clippingnode