cocos2d-x 字体使用方法浅析

一、首先是我用得比较熟悉的CCLableTTF
1、char * description();
该函数会得到当前label使用的字体名称及当前字体大小信息。
2、static CCLabelTTF * labelWithString(const char *label, const char *fontName, float fontSize);
这是一个静态初始化函数,该方法返回一个CCLabelTTF对象指针。
参数含义: label:需要显示的字符串,fontName:使用字体名称,fontSize:设置字体大小
附上cocos2d字体列表:http://blog.sina.com.cn/s/blog_82ca0a7701011271.html
3、bool initWithString(const char *label, const char *fontName, float fontSize);
初始化label,参数含义与上一个函数相同。这一函数与上一函数的区别为:本函数不是静态函数,也就是说你必须实例化一个CCLabelTTF对象之后才能调用本函数。
4、virtual void setString(const char label);
可以看到这是个虚函数,继承自CCLabelProtocol类。本函数的作用就是改变当前label显示的字符串。
5、virtual const char
getString(void);
这也是一个继承自CCLabelProtocol的虚函数,功能为得到当前label显示的字符串。
二、然后是CCLabelBMFont
1、static void purgeCachedData();
顾名思义,该函数作用为清空缓存数据。
2、static CCLabelBMFont * labelWithString(const char *str, const char *fntFile);
这也是一个静态初始化函数.
需要提供的参数信息为: (const char *)str:要显示的字符串,(const char *)fntFile:字体坐标文件
至于其具体工作原理就不深究了,这里只要知道使用方法就行。
3、bool initWithString(const char *str, const char *fntFile);
参数含义同上。
4、virtual void setString(const char label);
virtual const char
getString(void);
这两个函数同样是继承自CCLabelProtocol的函数。作用就不多说了。
三、最后是CCLabelAtlas,这个比较复杂,所以放在最后讲
需要注意的是,使用这个类提供的方法需要你提供字体图片,而且CCLabelAtlas只支持定尺寸大小的字体显示,也就是说你给出的字体图片中的每个字符必须等尺寸。初始化的时候也必须给出每个字符的宽和高,以便于程序自动取图。
其工作原理个人认为是根据ACSII工作,给出第一个字符,程序自动得到其ASCII码,然后再依次得到需要显示的字符串中每个字符的ASCII码并计算其位置,所以字体图片中的字符必须按ACSII码排列,不然得不到想要的字符串
四、总结
1、项目需要,所以看了看字体相关的东西,可能还很浅显,有错的地方希望大家给予指正。
2、如果有更好的见解或建议,欢迎指教或者一起讨论
3、本文只是给出一般接口及参数的介绍,如果想深入了解其继承关系或三种方式的工作效率
http://zhongyi.sina.com/zx/news/310312.shtml http://zhongyi.sina.com/zx/news/310311.shtml http://zhongyi.sina.com/zx/news/310308.shtml http://zhongyi.sina.com/zx/news/310307.shtml http://zhongyi.sina.com/zx/news/310306.shtml http://zhongyi.sina.com/zx/news/310300.shtml http://zhongyi.sina.com/zx/news/310298.shtml http://zhongyi.sina.com/zx/news/310295.shtml http://zhongyi.sina.com/zx/news/310294.shtml http://zhongyi.sina.com/zx/news/310291.shtml http://zhongyi.sina.com/zx/news/310288.shtml http://zhongyi.sina.com/zx/news/310286.shtml http://zhongyi.sina.com/zx/news/310283.shtml http://zhongyi.sina.com/zx/news/310280.shtml http://zhongyi.sina.com/zx/news/310279.shtml http://zhongyi.sina.com/zx/news/310278.shtml http://zhongyi.sina.com/zx/news/310275.shtml http://zhongyi.sina.com/zx/news/310273.shtml http://zhongyi.sina.com/zx/news/310270.shtml http://zhongyi.sina.com/zx/news/310268.shtml http://zhongyi.sina.com/zx/news/310265.shtml http://zhongyi.sina.com/zx/news/310260.shtml http://zhongyi.sina.com/zx/news/310258.shtml http://zhongyi.sina.com/zx/news/310256.shtml http://zhongyi.sina.com/zx/news/310255.shtml http://zhongyi.sina.com/zx/news/310253.shtml http://zhongyi.sina.com/zx/news/310252.shtml http://zhongyi.sina.com/zx/news/310248.shtml http://zhongyi.sina.com/zx/news/310245.shtml http://zhongyi.sina.com/zx/news/312111.shtml http://zhongyi.sina.com/zx/news/312110.shtml http://zhongyi.sina.com/zx/news/312107.shtml http://zhongyi.sina.com/zx/news/312105.shtml http://zhongyi.sina.com/zx/news/312103.shtml http://zhongyi.sina.com/zx/news/312101.shtml http://zhongyi.sina.com/zx/news/312100.shtml http://zhongyi.sina.com/zx/news/312098.shtml http://zhongyi.sina.com/zx/news/312097.shtml http://zhongyi.sina.com/zx/news/312095.shtml http://zhongyi.sina.com/zx/news/312094.shtml http://zhongyi.sina.com/zx/news/312093.shtml http://zhongyi.sina.com/zx/news/312091.shtml http://zhongyi.sina.com/zx/news/312090.shtml http://zhongyi.sina.com/zx/news/312089.shtml http://zhongyi.sina.com/zx/news/312088.shtml http://zhongyi.sina.com/zx/news/312087.shtml http://zhongyi.sina.com/zx/news/312086.shtml http://zhongyi.sina.com/zx/news/312085.shtml http://zhongyi.sina.com/zx/news/312083.shtml http://zhongyi.sina.com/zx/news/312082.shtml http://zhongyi.sina.com/zx/news/312081.shtml http://zhongyi.sina.com/zx/news/312080.shtml http://zhongyi.sina.com/zx/news/312078.shtml http://zhongyi.sina.com/zx/news/312077.shtml http://zhongyi.sina.com/zx/news/312076.shtml http://zhongyi.sina.com/zx/news/312075.shtml http://zhongyi.sina.com/zx/news/312073.shtml http://zhongyi.sina.com/zx/news/312072.shtml

看到广告投放者们都这么专心的学习cocos,我辈汗颜。。:6::6:

mark:2::2::2::2::2::2: