Cocos2d-x3.0标签类Label-创新互联

Cocos2d-x 3.0

Cocos2d-x 3.0标签类Label

创新互联是一家专业提供文水企业网站建设,专注与网站设计、成都网站建设、html5、小程序制作等业务。10年已为文水众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。
static Label* createWithSystemFont(conststd::string &text,             //是要显示的文字                             
                  const std::string& font,                                                       //系统字体名  
                  float fontSize,                                                            //字体的大小  
                  const Size& dimensions = Size::ZERO,                            //在屏幕上占用的区域大小,可省略  
                  TextHAlignment  hAlignment = TextHAlignment::LEFT,          //文字横向对齐方式,可省略  
                  TextVAlignment  vAlignment = TextVAlignment::TOP)   //文字纵向对齐方式,可省略  
   
static Label* createWithTTF(conststd::string & text,  
         const std::string &  fontFile,                                                              //字体文件  
         float fontSize,  
         const Size &  dimensions = Size::ZERO,                                           //可省略  
         TextHAlignment          hAlignment= TextHAlignment::LEFT,          //可省略  
         TextVAlignment           vAlignment= TextVAlignment::TOP              //可省略  
    )       
   
static Label* createWithTTF(constTTFConfig& ttfConfig,  
         const std::string& text,  
         TextHAlignment alignment =TextHAlignment::LEFT,  
         int maxLineWidth = 0  
    )  
   
static Label* createWithBMFont(conststd::string& bmfontFilePath,          //位图字体文件  
         const std::string&  text,                                                              
         const TextHAlignment& alignment =TextHAlignment::LEFT, //可省略  
         int maxLineWidth = 0,                                                                       //可省略  
         const Point&  p_w_picpathOffset = Point::ZERO                                //可省略  
    )


Cocos2d-x 3.0标签类Label

bool HelloWorld::init()  
{  
   if ( !Layer::init() )  
   {  
       return false;  
   }  
     
   Size visibleSize = Director::getInstance()->getVisibleSize();  
   Point origin = Director::getInstance()->getVisibleOrigin();  
   auto closeItem = MenuItemImage::create(  
                                          "CloseNormal.png",  
                                          "CloseSelected.png",  
                                 CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));  
     
    closeItem->setPosition(Point(origin.x+ visibleSize.width - closeItem->getContentSize().width/2 ,  
                                origin.y + closeItem->getContentSize().height/2));  
   
    
   auto menu = Menu::create(closeItem, NULL);  
   menu->setPosition(Point::ZERO);  
   this->addChild(menu, 1);  
     
    autolabel1 = Label::createWithSystemFont("Hello World1","Arial", 36);                                   ①  
    label1->setPosition(Point(origin.x+ visibleSize.width/2,  
         origin.y + visibleSize.height - 100));  
    this->addChild(label1,1);  
   
    autolabel2 = Label::createWithTTF("Hello World2", "fonts/MarkerFelt.ttf", 36);                       ②  
    label2->setPosition(Point(origin.x+ visibleSize.width/2,  
         origin.y + visibleSize.height - 200));  
    this->addChild(label2,1);  
   
    autolabel3 = Label::createWithBMFont("fonts/BMFont.fnt", "HelloWorld3");                            ③  
    label3->setPosition(Point(origin.x+ visibleSize.width/2,  
         origin.y + visibleSize.height - 300));  
    this->addChild(label3,1);  
   
    TTFConfigttfConfig("fonts/Marker Felt.ttf",  
         36,  
         GlyphCollection::DYNAMIC);                                                                                                  ④  
    autolabel4 = Label::createWithTTF(ttfConfig, "Hello World4");                                                  ⑤  
    label4->setPosition(Point(origin.x+ visibleSize.width/2,  
         origin.y + visibleSize.height - 400));  
    this->addChild(label4, 1);  
   
    ttfConfig.outlineSize= 4;                                                                                                     ⑥  
    autolabel5 = Label::createWithTTF(ttfConfig, "Hello World5");                                                  ⑦  
    label5->setPosition(Point(origin.x+ visibleSize.width/2,  
         origin.y + visibleSize.height - 500));  
    label5->enableShadow(Color4B(255,255,255,128),Size(4, -4));                                        ⑧  
    label5->setColor(Color3B::RED);                                                                                                 ⑨  
    this->addChild(label5,1);  
   
 return true;  
              }


第④行代码TTFConfig ttfConfig("fonts/Marker Felt.ttf", 36, GlyphCollection::DYNAMIC)是创建一个TTFConfig结构体变量,TTFConfig结构体的定义如下:

_ttfConfig(constchar* filePath = "",                                                                         //字体文件路径  
    int  size = 12,                                                                                            //字体大小  
    constGlyphCollection& glyphCollection = GlyphCollection::DYNAMIC,     //字体库类型  
    constchar * customGlyphCollection = nullptr,                                     //自定义字体库  
    booluseDistanceField = false,                                                                         //用户是否可缩放字体  
    intoutline = 0                                                                                                      //字体描边  
               )


更多精彩内容请关注史上最牛的cocos2d-x课程

cocos2d-x手机游戏开发实战》直播课程第一期

报名Cocos2d-x直播课程还送关东升老师iOS终身会员

课程链接:http://edu.51cto.com/pack/view/id-13.html

会员链接:http://edu.51cto.com/member/id-3.html

更多内容请关注Cocos2d-x系列图书《Cocos2d-x实战(卷Ⅰ):C++开发》

本书交流讨论网站:http://www.cocoagame.net

欢迎加入cocos2d-x技术讨论群:257760386、327403678

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:Cocos2d-x3.0标签类Label-创新互联
本文链接:http://myzitong.com/article/dogghc.html