1 .:
Previously, the Android high imitation iOS 7 IPhone was used To Unlock Slide To Unlock. This time, we will see how To make similar effects in cocos2d js.
By the way, I made advertisements for my company's games. Https://itunes.apple.com/cn/app/kuang-zhan-san-guo/id691116157? Mt = 8
2. effect principle
It is very simple, that is, a white image with both sides is moved from left to right on the title. However, a normal mobile phone can be used as a guide. We need to use the title as a template to capture white images. If the title is exceeded, it cannot be displayed. ClippingNode comes in handy!
3. Code Implementation
The following is the implementation of cocos2d js 2.2, the cocos2d-x should be similar.
Var MyLayer = cc. layer. extend ({isMouseDown: false, helloImg: null, helloLabel: null, circle: null, sprite: null, scaleRate: 0.8, init: function () {this. _ super (); var size = cc. director. getInstance (). getWinSize (); var clip = this. clipper (); var clipSize = clip. getContentSize (); clip. setPosition (cc. p (size. width/2, size. height/2); var gameTitle = cc. sprite. create (s_GameTitle); gameTitle. setScale (this. scaleRate); var spark = cc. sprite. create (s_Spark); clip. addChild (gameTitle, 1); // Add the title first and it will be displayed completely, because it is the same size as the template spark. setPosition (-size. width/2, 0); clip. addChild (spark, 2); // clip will be dropped. setScaleY (1.2); this. addChild (clip, 4); var moveAction = cc. moveTo. create (0.6, cc. p (clipSize. width, 0); var moveBackAction = cc. moveTo. create (0.6, cc. p (-clipSize. width, 0); var seq = cc. sequence. create (moveAction, moveBackAction); var repeatAction = cc. repeatForever. create (seq); spark. runAction (repeatAction); // repeated action for moving left and right}, clipper: function () {// create a template with the title as the size, var clipper = cc will be dropped if the header is exceeded. clippingNode. create (); var gameTitle = cc. sprite. create (s_GameTitle); gameTitle. setScale (this. scaleRate); clipper. setstenpencil (gameTitle); // create a clipper template with the title as the size. setAlphaThreshold (0); clipper. setContentSize (cc. size (gameTitle. getContentSize (). width, gameTitle. getContentSize (). height); return clipper ;}}); var MyScene = cc. scene. extend ({onEnter: function () {this. _ super (); var layer = new MyLayer (); this. addChild (layer); layer. init ();}});