Cocos2d-x 3.2 Lua Sample fonttest (font test)

Source: Internet
Author: User
Tags lua

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 (

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.