Cocostudio學習筆記(5) Text + TextAtlas + TextBMFont,cocostudio

來源:互聯網
上載者:User

Cocostudio學習筆記(5) Text + TextAtlas + TextBMFont,cocostudio
下午一群大學生到我們公司參觀學習,搞得我好緊張,於是滔滔不絕的給他們介紹了如何開發一款遊戲...

今晚研究的控制項就是三個label:Text,TextAtlas,TextBMFont

我先在cocostudio中將三種標籤都拖入到情境中,分別命名為:label,atlas,bitMap。最後匯出工程,在cocos2dx載入該Widget

cocos2d::ui::Widget* labelUI = GUIReader::getInstance()->widgetFromJsonFile("LabelUI/LabelUI_1.json");this->addChild(labelUI,2);
這裡可能有人會說:既然之前已經聲明了cocos2d::ui的範圍,那在這裡為什麼不直接使用Widget呢?我的回答是,我也是新手,對於這些API的寫法還不夠習慣,所以只能通過這種重複書寫的方式加深印象。

一、先看Text
1、將label從Widget中取出來,代碼如下:
Text* m_label = static_cast<Text*>(Helper::seekWidgetByName(labelUI,"label"));m_label->setPosition(Point(300,300));

2、看下Text的源碼:
static Text* create();//建立static Text* create(const std::string& textContent,const std::string& fontName,int fontSize);void setText(const std::string& text);//設定顯示的文本const std::string& getStringValue();獲得text中的常值內容ssize_t getStringLength();//獲得text中字串長度
其實和cocos2dx中的Label的使用方法差不多,這裡就不多看了。

二、TextAtlas
1、將label中Widget中取出

TextAtlas* m_atlas = static_cast<TextAtlas*>(Helper::seekWidgetByName(labelUI,"atals"));m_atlas->setPosition(Point(400,300));

2、無語

三、TextBMFont
1、將label從Widget中取出

TextBMFont* m_bmf = static_cast<TextBMFont*>(Helper::seekWidgetByName(labelUI,"bitMap"));m_bmf->setPosition(Point(200,300));

2、無語

四、總結,上面我之所以沒有做更深入的介紹,是因為我發現cocostudio中的Text與cocos2dx中的Label幾乎沒啥差別,所以我也就懶得介紹。之前部落格對3.0後的Label介紹得都挺清楚了。

尊重原創,轉載請註明來源:http://blog.csdn.net/star530/article/details/37370285



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.