cocos2d-x——CCLabelTTF(基本文本)

CCLabelTTF類是使用起來最方便的類,最常用的創建標籤 的方法有兩種方法:

方法一:

static  CCLabelTTF *create(const  char *string,const char *fontName,float fontSize);

參數分別是:標籤顯示的內容,使用的字體 以及字符大小,這裏的字體一般指的就是系統字庫,當然我們也可以爲它提供,ttf文件。

    //設置字符串和字體,及字號。

   CCLabelTTF *labelttf=CCLabelTTF ::create("nihaozhonghuo","Thonburi"48);

    labelttf->setColor(ccc3(255,00));//設置顏色

    labelttf->setPosition(ccp(200,300));//設置顯示的位置,

   addChild(labelttf);

    //用賦值的方法。

    CCLabelTTF *labelttf2=CCLabelTTF::create();

    labelttf2->setString("string");//設置字符串

    labelttf2->setFontName("Thonburi");//設置字體。

    labelttf2->setFontSize(50);//設置字號。

    labelttf2->setColor(ccc3(0,2550));//設置顏色

    labelttf2->setPosition(ccp(200,800));//設置顯示的位置

    addChild(labelttf2);

方法二:

可以設定Label矩形的大小,設置Label水平位置(居右,居中,居右)和垂直位置等。

/*1個參數爲設置的字符串,第2個參數爲字體,第3個參數是字號,

    4號參數是設置Label矩形顯示框的大小,第5個參數是左右對齊方式,第6個參數是上下對齊方式*/

    CCLabelTTF *labelttf3=CCLabelTTF::create(" Alignment","Helvetica",48,CCSizeMake(256,32),kCCTextAlignmentLeft,kCCVerticalTextAlignmentTop);

    labelttf3->setColor(ccc3(0,255255));//設置顏色,

    labelttf3->setPosition(ccp(400,800));//設置位置

    addChild(labelttf3);


     kCCTextAlignmentLeft——左對齊。

      kCCTextAlignmentCenter——中心對齊。

      kCCTextAlignmentRight——右對齊



      kCCVerticalTextAlignmentTop——頂對齊

      kCCVerticalTextAlignmentCenter——中心對齊

      kCCVerticalTextAlignmentBottom——底對齊

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章