https://blog.csdn.net/wwj_748/article/details/38587241
This blog describes the fonttest example in the LUA test project in Cocos2d-x 3.2, which uses font files to create the font styles we want:
The first argument is text, the second parameter is the TTF font file, the third argument is the font size, the fourth argument is the block size, the fifth parameter is the text horizontal alignment, and the sixth is the text portrait alignment.
Example Effect Chart:
Sample code: (Note: The individual file is not operational, specific reference to lua-tests)
[JavaScript] View Plain copy--4 labeled tag local ktaglabel1 = 0 Local kTagLabel2 = 1 local ktaglabel3 = 2 Local kTagLabel4 = 3 -- Font list local fontlist = { "Fonts/a damn mess.ttf", fonts/ Abberancy.ttf ", " Fonts/abduction.ttf ", " Fonts/paint boy.ttf ", " Fonts/schwarzwald regular.ttf ", " fonts/scissor Cuts.ttf " } local fontcount = table.getn (fontlist -- get the number of table elements Cclog ("font count = " ...). FontCount) local valignidx = 1 local verticalalignment = {   CC. VERtical_text_alignment_top, -- Align Top cc. vertical_text_alignment_center, -- Center Align   CC. vertical_text_alignment_bottom, -- Bottom Alignment } Local valigncount  = TABLE.GETN (verticalalignment) --[[ =============== Display fonts =============== ]]-- local function showfont (Ret, pFont) cclog ("valignidx="). VALIGNIDX) local s = cc. Director:getinstance (): getwinsize ()-- window size local blocksize = cc.size (s.width/3, 200)-- block size local fontsize = 26--font size -- Remove sub-node ret:removechildbytag (KTAGLABEL1) according to tag true) ret:removechildbytAG (Ktaglabel2, true) ret:removechildbytag (ktaglabel3, true) ret:removechildbytag (ktaglabel4, true) -- static label * createwithttf (const std::string & text, const std::string & Fontfile, float fontsize, const size & dimensions = size::zero, --TextHAlignment hAlignment = TextHAlignment::LEFT,TextVAlignment Valignment = textvalignment::top) -- The first parameter is text, The second argument is the font style, the third argument is the font size, the fourth argument is the block size, the fifth argument is the text horizontally aligned, and the sixth argument is text vertical   LOCAL TOP = CC . Label:createwithttf (pfont, pfont, 24) local left = cc. Label:createwithttf ("Alignment left", pfont, fontsize, Blocksize, cC.TEXT_ALIGNMENT_LEFT, VERTICALALIGNMENT[VALIGNIDX]) local center =  CC. Label:createwithttf (