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