cocos2d-x 3.0 final 中文顯示

來源:互聯網
上載者:User

cocos2d-x 3.0的中文顯示很簡單,首先,你需要一個xml檔案儲存中文,還需要一個能顯示中文的TTF檔案


<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>miaoshu</key><string>滑動手指,相同數字磁塊合併相加,目標2048!</string></dict></plist>

如上,為什麼我用的是繁體,因為官方給的是能顯示繁體的TTF,那就將就用吧,官方tests例子中的繁體TTF檔案為wt021.ttf


下面就是直接使用,


TTFConfig config1("fonts/wt021.ttf",20);auto strings = FileUtils::getInstance()->getValueMapFromFile("strings.xml");std::string miaoshu  = strings["miaoshu"].asString();auto labelts = Label::createWithTTF(config1,miaoshu,TextHAlignment::LEFT);labelts->setTextColor(Color4B(216,28,87,255));labelts->setPosition(Point(origin.x + visibleSize.width/10,origin.y + visibleSize.height/9*7));labelts->setAnchorPoint(Point::ZERO);this->addChild(labelts);

效果如下


看看,連換行都一併解決了.


還有一種更簡潔的辦法,就是使用 FileUtils::getInstance()->getStringFromFile("strings.xml");意思就是將string.xml檔案中的內容當作一個超級長的字串顯示,strings.xml裡面是純文字哦,不是xml格式哦,我寫strings.xml是懶換檔案名稱的,當然,換行什麼的都在

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.