Cocos2d-x3.1 uses ClippingNode to implement title shining Effects

Source: Internet
Author: User

Cocos2d-x3.1 uses ClippingNode to implement title shining Effects
1. Master the principles and use of ClippingNode 2. Create a Cocos project 3. Add the following code to the HelloWorld. cpp Code:

Auto clip = ClippingNode: create (); // create a crop node auto gameTitle = Sprite: create ("game_title.png"); clip-> setstencel (gameTitle ); // set the cropping template clip-> setAlphaThreshold (0); // set the transparency threshold clip-> setContentSize (Size (gameTitle-> getContentSize (). width, gameTitle-> getContentSize (). height); // set the crop node size auto clipSize = clip-> getContentSize (); // obtain the crop node size clip-> setPosition (Vec2 (visibleSize. width/2, visibleSize. height/2); // set the location log ("clipSize. x = % lf, clipSize. y = % lf ", clipSize. width, clipSize. height); // log to check the location. Useless auto gameTitle_show = Sprite: create ("game_title.png"); // create the object to be displayed auto spark = Sprite :: create ("spark.png"); // create a shining genie clip-> addChild (gameTitle_show, 1); // place the content to be displayed in the cropping node, in fact, you can directly clip-> addChild (gameTitle, 1); here to change the display content spark-> setPosition (Vec2 (-visibleSize. width/2, 0); // set the clip position of the shining genie> addChild (spark, 2); // Add the shining genie to the cropping node addChild (clip, 4 ); // Add the cropping node auto moveAction = MoveTo: create (2.6, Vec2 (clipSize. width, 0); // create the sprite node's action auto moveBack = MoveTo: create (2.6, Vec2 (-clipSize. width, 0); auto seq = Sequence: create (moveAction, moveBack, NULL); auto repreatAction = RepeatForever: create (seq); spark-> runAction (repreatAction ); // repeated actions on the sprite Node



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.