加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Label

发布时间:2020-12-14 17:14:06 所属栏目:百科 来源:网络整理
导读:说明 引擎版本: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

说明

引擎版本: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>

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读