有些时候需要在界面上显示些文字,自然涉及到字体的问题
显示文字使用CCLabelTTF即可,创建方法是
CCLabelTTF(const char* text, const char* font, int size);
系统自带了很多字体,不多说了,直接上代码和图吧
static std::string _font[] = { "AppleGothic", "HiraKakuProN-W6", "HiraKakuProN-W3", "MarkerFelt-Thin", "STHeitiK-Medium", "STHeitiK-Light", "TimesNewRomanPSMT", "Helvetica-Oblique", "Helvetica-BoldOblique", "Helvetica", "Helvetica-Bold", "TimesNewRomanPS-BoldMT", "TimesNewRomanPS-BoldItalicMT", "TimesNewRomanPS-ItalicMT", "Verdana-Bold", "Verdana-BoldItalic", "Verdana", "Verdana-Italic", "Georgia-Bold", "Georgia", "Georgia-BoldItalic", "Georgia-Italic", "ArialRoundedMTBold", "TrebuchetMS-Italic", "TrebuchetMS", "Trebuchet-BoldItalic", "TrebuchetMS-Bold", "STHeitiTC-Light", "STHeitiTC-Medium", "GeezaPro-Bold", "GeezaPro", "Courier", "Courier-BoldOblique", "Courier-Oblique", "Courier-Bold", "ArialMT", "Arial-BoldMT", "Arial-BoldItalicMT", "Arial-ItalicMT", "STHeitiJ-Medium", "STHeitiJ-Light", "ArialHebrew", "ArialHebrew-Bold", "CourierNewPS-BoldMT", "CourierNewPS-BoldItalicMT", "CourierNewPSMT", "Thonburi-Bold", "AmericanTypewriter", "AmericanTypewriter-Bold", "STHeitiSC-Medium", "STHeitiSC-Light", "HelveticaNeue", "HelveticaNeue", "HelveticaNeue-Bold", "Zapfino", "" }; // on "init" you need to initialize your instance bool TextAndFont::init() { ////////////////////////////// // 1. super init first if ( !MenuLayer::init() ) { return false; } CCLabelTTF* label; for(int i=0; _font[i].length(); ++i) { label = CCLabelTTF::create(_font[i].c_str(), _font[i].c_str(), 20); addChild(label); label->setPosition(ccp(150, __winSize.height - i*20 - 20)); } enableMove(); return true; }
这些字体在ios中有,有些在windows下没有的,所以如果你的代码在windows下,效果不一样不要惊讶。