cocos2d-x教程3 CCLabelTTF的使用

来源:互联网 发布:mac ant root 编辑:程序博客网 时间:2024/05/29 04:19

HelloWorldScene.cpp

#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"


using namespace cocos2d;

using namespace CocosDenshion;


CCScene* HelloWorld::scene()

{

   CCScene *scene =CCScene::create();

    HelloWorld *layer =HelloWorld::create();

    scene->addChild(layer);

   return scene;

}


// on "init" you need to initialize your instance

bool HelloWorld::init()

{

   if ( !CCLayer::init() )

    {

        return false;

    }

    

//------CCLabelTTF

    CCLabelTTF* pLabel =CCLabelTTF::create("CCLabelTTF-Thonburi","Thonburi",24);

    pLabel->setPosition(ccp(170,280) );

   this->addChild(pLabel);


   CCLabelTTF* pLabel2 =CCLabelTTF::create();

    //设置字体大小

    pLabel2->setFontSize(20);

    //设置字符串

    pLabel2->setString("CCLabelTTF-Helvetica"); 

    pLabel2->setPosition(ccp(170,250) );

   this->addChild(pLabel2);

    

//------CCLabelAtlas

//    CCLabelAtlas* label = CCLabelAtlas::create(<#const char *string#>, <#const char *charMapFile#>, <#unsigned int itemWidth#>, <#unsigned int itemHeight#>, <#unsigned int startCharMap#>)

    

   CCLabelAtlas* label =CCLabelAtlas::create("Atlas-823","testfont.png",48,64, ' ');

    label->setPosition(ccp(0,190));

   addChild(label);

    //设置字体颜色

    label->setColor(ccc3(255,0,0));

    

    CCLabelAtlas* label2 =CCLabelAtlas::create("LabelAtlas","testfont.plist");

    label2->setPosition(ccp(0,140));

   addChild(label2);

    

//------CCLabelBMFont

    CCLabelBMFont* labelBM =CCLabelBMFont::create("Himi站立","testChinese.fnt");

    labelBM->setPosition(ccp(180,100));

   addChild(labelBM);

    

    return true;

}



原创粉丝点击