In the cocos2d-x, the font file needs to be saved in the fonts folder, which is automatically added if the fonts/is not in the fonts path.
If the font name does not have a. TTF suffix, the suffix is automatically added.
Unsigned Char * Ccfreetypefont: loadfont ( Const Char * Pfontname, ssize_t * Size) {STD :: String Lowercase (pfontname); STD :: String PATH (pfontname ); For (Unsigned Int I = 0 ; I <lowercase. Length (); ++ I) {lowercase [I] = Tolower (lowercase [I]);} If (STD :: String : NPOs = lowercase. Find ( " Fonts/ " ) {Path = " Fonts/ " ; Path + = Pfontname ;} If (STD :: String : NPOs = lowercase. Find ( " . TTF " ) {Path + = " . TTF " ;} STD :: String Fullpath = fileutils: getinstance ()->Fullpathforfilename (path. c_str ()); Return Fileutils: sharedfileutils ()-> getfiledata (fullpath. c_str (), " RB " , Size );}
String: NPOs is-1, indicating that no substring is found. The find method is used to find whether fonts is included in the font name.
Location of TTF font files in cocos2d-x