Label

前端之家收集整理的这篇文章主要介绍了Label前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

说明

引擎版本:cocos2d-x 3.4 编译器:visual studio 2013 UI编辑器:Cocos Studio v1.6.0.0

Label(cocos/2d模块下)

常用API如下:

  • createWithSystemFont


    
    
/** Creates a label with an initial string,font[font name or font file],font size,dimension in points,horizontal alignment and vertical alignment. * @warning It will generate texture by the platform-dependent code */static Label* createWithSystemFont(const std::string& text, font float fontSize Size dimensions =ZERO TextHAlignment hAlignment TextHAlignmentLEFT TextVAlignment vAlignment TextVAlignmentTOP);

  • createWithTTF


     
     
* @warning Not support font name.* @warning Cache textures for each different font size or font file.*/ Label createWithTTF fontFile);

  • createWithBMFont

需要一个图片文件(*.png)和一个字体文件(*.fnt)
/* Creates a label with an FNT file,an initial string,horizontal alignment,max line width and the offset of image*/ createWithBMFont bmfontFilePath alignment int maxLineWidth 0 Vec2 imageOffset );

//可以得到相应下标的Sprite,可以单独设置virtual Sprite getLetter(int lettetIndex
  • createWithCharMap
  • //@startCharMap 为ANSIC码,即'0'为48 createWithCharMap charMapFile itemWidth itemHeight startCharMap);//利用纹理创建(Texture2D texture//eg:Texture2D texture TextureCachegetInstance()->addImage("labelatlasimg.png");Label label createWithCharMap(texture2432 '0'//.plist文件创建 plistFile .plist文件格式如下:
  • <?xml version="1.0" encoding"UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"><dict><key>version</key> <!-- plist版本 --><integer>1</integer>textureFilename<!-- 字符图片资源: digit.png --><string>labelatlasimg.png</string>itemWidth<!-- 每个字符的宽: 24 -->24itemHeight<!-- 每个字符的高: 32 -->32firstChar<!-- 起始字符 : '0' -->48</dict></plist>

    猜你在找的Cocos2d-x相关文章