Cocos2d js ClippingNode creates special effects with titles shining

Source: Internet
Author: User

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 ();}});

 

 

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.