cocos2dx3.2 Crazy Tetris to draw irregular block masks (use of Clippingnode)

Source: Internet
Author: User
Tags addchild

Before you have thought about the elimination and area determination issues that you might encounter, the next question is how to display these irregular shapes that can be derived from the elimination.

Here, I used the clippingnode(mask). The introduction of Clippingnode on the Internet is very careful, so I'm just here to say briefly:

Like his name, he is also a node, so you can refer to my first blog post about the node tree, and when you use it, you need to add it to another node.

Note that you need to add a template (stencil) and a backplane to it. stencil means something like a mold, and it can be imagined that if we define the shape of the mold and then print it on a plate with a large pattern, it will only show this part of the mold shape on the backplane, or the rest of the mold shape.

How to add a template:

Static clippingnode* Create (Node *stencil);

The construction method of direct belt template;


void Setstencil (Node *stencil);

Add a template


Add a backplane directly using the AddChild method.

Simply say so much, the rest of the function can refer to the information on the Internet.

Here, as we can know to display the vertex information of the graph, so it is convenient to construct a template, the display of irregular graphics. This piece of code should of course be placed in the initialization function of the Baseblock block class so that it automatically completes the mask each time it is initialized.

The code is as follows:

void Baseblock::initform (std::vector<cocos2d::vec2 *> * shapevecs, std::vector<int> * shapeVecAmount, int Shapeamount, color4b color) {Vec2 origin = Director::getinstance ()->getvisibleorigin (); this->shapeamount = Shapeamount;this->shapevecamount = Shapevecamount;this->shapevecs = Shapevecs;auto stencil = DrawNode::create () Auto BODY = Physicsbody::create (); for (int i=0; i<shapeamount; i++) {Auto shape = physicsshapepolygon::create ( Shapevecs->at (i), Shapevecamount->at (i)); shape->setrestitution (0.5); Body->addshape (shape); stencil- >drawpolygon (Shapevecs->at (i), Shapevecamount->at (i), color4f (1, 1, 0, 1), 0, color4f (1, 1, 0, 1));} Auto Clipper = Clippingnode::create (); clipper->setzorder (0); Clipper->setstencil (stencil);stencil-> SetPosition (Stencil->getpositionx () + this->getcontentsize (). WIDTH/2, Stencil->getpositiony () + this-> Getcontentsize (). height/2) This->color = Color;auto back = Layercolor::create (This->color, this->gettexturerect (). Getmaxx (), This->gettexturerect (). Getmaxy ()); Clipper->addchild (back);this-> AddChild (clipper); This->setphysicsbody (body);}

For a list of other blogs related to making games, I putUse cocos2dx3.2 to make a gravity version of Tetris (Crazy Tetris)



cocos2dx3.2 Crazy Tetris to draw irregular block masks (use of Clippingnode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.