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.