说明
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
/* 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
//@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文件格式如下:
- createWithCharMap
<?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>