Cocos2dx sprite cropping display ClippingNode

Source: Internet
Author: User

Cocos2dx sprite cropping display ClippingNode

ClippingNode can be used to crop a node. You can cut an image node based on a template to generate a node display of any shape.

Example

 

Auto bg = LayerColor: create (Color4B (255,255,255,255); this-> addChild (bg,-1); // 1 auto stencel = Sprite: create(CloseNormal.png ); auto clipper = ClippingNode: create (); clipper-> setstencer (stencer); // you can specify a cropping template. // 3 clipper-> setInverted (true ); // set clipper-> setAlphaThreshold (0) for the baseboard to be visible; // set the Alpha value of the baseboard to 0 this-> addChild (clipper); // 4 auto content = Sprite :: create(HelloWorld.png); // The cropped content clipper-> addChild (content); // 5 clipper-> setPosition (Vec2 (visibleSize. width/2 + origin. x, visibleSize. height/2 + origin. y ));

When clipper-> setInverted (true );

When clipper-> setInverted (false); displays an image of the template size, equivalent to a baseboard sprite that only displays images in the non-transparent area of the template.

Therefore, to display a circular Avatar in the game, you do not need to generate a set of resources. You only need a solid circular image as a template.

 

 

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.