Cocos2d-x using Clipingnode to do the game mask making Novice Guide

Source: Internet
Author: User
Tags addchild

original works, reproduced please indicate : http://blog.csdn.net/jackystudio/article/details/17160973


Novice Guide is necessary in the game (in addition to the wonderful MT with a section of animation to start), but also the first impression of the game, the importance of self-evident. Masks are generally used in the form of highlighting to highlight the focus, while shielding other functions. Here is a simple introduction to the implementation of the game mask, and give an example.


1.CCClipingNode

The Ccclipingnode is a clip-on node that is simple to understand:

(1) First, it is a node that inherits from Ccnode, so it can be put into cclayer,ccscene,ccnode like a normal node.

(2) As a node, it can be used as a container to host other nodes and sprites. I called it the bottom plate.

(3) If you want to crop a node, it needs to give the cropped part, this clipping area, I call it a template.

So the Ccclipingnode clipping node in the composition = Backplane + template, and on display = backplane-template. I wonder if this explanation will be good to understand.



2.API

The use of Ccclipingnode is still relatively simple, as for the display plate or template, the alpha value of the setting, these are not good to say clearly, oneself more than a few times to know what it means to use.

[CPP]View plain copy//Create a clipping node with no template static ccclippingnode* create ();      Create a clipping node using a node as a template static ccclippingnode* create (Ccnode *pstencil);      Initializes a clipping node without a template virtual bool init ();      Initializes the clipping node with a node as a template virtual bool init (Ccnode *pstencil);   To set/Get the template, note that the template needs to be retain.   ccnode* getstencil () const;      void Setstencil (Ccnode *pstencil);   Setting the alpha value (0~1), which is important, the cropping is keyed by pixels, so only the template pixels larger than this alpha value will be drawn//default is 1, that is, fully cropped.   Glfloat getalphathreshold () const;      void Setalphathreshold (Glfloat falphathreshold);   The default is False, which is used to set the display backplane or template bool isinverted () const; void setinverted (bool binverted);

3. The example is implemented in Init:

[CPP] view plain copy ccsize visiblesize=ccdirector::shareddirector ()->getvisiblesize (); ccsprite* background = ccsprite::create ("Helloworld.png");//Create Background background->setposition (CCP (visiblesize.width/   2,VISIBLESIZE.HEIGHT/2));      This->addchild (Background,ktagbackground); Clip=ccclippingnode::create ();//Create clipping node, member variable clip->setinverted (TRUE);//Set Backplane visible Clip->setalphathreshold (0.0f) ;//Set Alpha to 0 this->addchild (clip,ktagclipnode);//Add Crop node cclayercolor* back=cclayercolor::create (CCC4 (0,0,0,200   )); Clip->addchild (back);//Add a black, transparent (looking gray) backplane//template for the cropping node if you want to use it elsewhere, remember retain.

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.