Cc. LabelAtlas in Cocos2d-JS

Source: Internet
Author: User

Cc. LabelAtlas in Cocos2d-JS
Cc. labelAtlas is an image set label, in which Atlas is intended to be "Atlas" and "image set". The text displayed by this label is extracted from an image set, so cc is used. labelAtlas requires additional image set files. Cc. LabelAtlas is much faster than cc. LabelTTF. Each character in cc. LabelAtlas must have a fixed height and width.
As shown in the cc. LabelAtlas class diagram, cc. LabelAtlas indirectly inherits the cc. Node class, which has the basic features of cc. Node and directly inherits cc. AtlasNode.
Cc. LabelAtlas class diagram

To display the Hello World text shown in, use cc. LabelAtlas.

Hello World text implemented by cc. LabelAtlas

The main code for cc. LabelAtlas to implement the Hello World text is as follows:
Var HelloWorldLayer = cc. Layer. extend ({sprite: null, ctor: function () {this. _ super ();...... // Create and initialize the label var helloLabel = new cc. labelAtlas (Hello World, res. charmap_png, 48, 66,); ① helloLabel. x = size. width/2-helloLabel. getContentSize (). width/2; helloLabel. y = size. height-helloLabel. getContentSize (). height; this. addChild (helloLabel, 5 );...... Return true ;}});

The first line of the above Code is to create a cc. labelAtlas object. The first parameter of the constructor is the text to be displayed, the second parameter is the image set file (see figure), the third parameter is the character height, and the fourth parameter is the character width; the fifth parameter is the start character.

To prevent hard coding problems, the image set file should use res. charmap_png to indicate the resource path. The variable res. charmap_png is the resource Name Defined in resource. js. The resource. js code is as follows:
var res = {    HelloWorld_png : res/HelloWorld.png,    CloseNormal_png : res/CloseNormal.png,    CloseSelected_png : res/CloseSelected.png,    charmap_png : res/fonts/tuffy_bold_italic-charmap.png};

 

 

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.