码迷,mamicode.com
首页 > Windows程序 > 详细

查看3.x NewLabelApi 笔记

时间:2014-12-13 18:04:49      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:3.x   cocos2dx   label   自适应   api   

  • Label 自适应宽度

    1. setmaxLineWidth

      label->setMaxLineWidth(labelWidth);
      
    2. setDimensions(unsigned int width,unsigned int height)

      这个也是修改maxLineWidth
      
  • 旋转,跳动的字符,使用fnt创建的字符串,可以通过getLetter获取到某个字符,然后执行action即可

    auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas");
     auto BChar = (Sprite*) label->getLetter(0);
    auto FChar = (Sprite*) label->getLetter(7);
    auto AChar = (Sprite*) label->getLetter(12);
    
    auto rotate = RotateBy::create(2, 360);
    auto rot_4ever = RepeatForever::create(rotate);
    
    auto scale = ScaleBy::create(2, 1.5f);
    auto scale_back = scale->reverse();
    auto scale_seq = Sequence::create(scale, scale_back,nullptr);
    auto scale_4ever = RepeatForever::create(scale_seq);
    
    auto jump = JumpBy::create(0.5f, Vec2::ZERO, 60, 1);
    auto jump_4ever = RepeatForever::create(jump);
    
    auto fade_out = FadeOut::create(1);
    auto fade_in = FadeIn::create(1);
    auto seq = Sequence::create(fade_out, fade_in, nullptr);
    auto fade_4ever = RepeatForever::create(seq);
    
    BChar->runAction(rot_4ever);
    BChar->runAction(scale_4ever);
    FChar->runAction(jump_4ever);
    AChar->runAction(fade_4ever);
    
  • 修改Label颜色

    使用Label成员函数setColor
    
  • 一次性创建很多字符串,使用相同的FNT,速度会快很多

    for ( int i=0 ; i < 100;i ++ ) 
    {
        char str[6] = {0};
        sprintf(str, "-%d-", i);
        auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", str);
        addChild(label);
    
        auto s = Director::getInstance()->getWinSize();
    
        auto p = Vec2( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
        label->setPosition( p );
    }
    
  • Label 默认anchorPoint为(0.5, 0.5)

    可以修改
    
  • VS2012 好恶心的“美好的一天啊”,没有“啊”在VS2012会报错啊,我勒个去

    // Adding "啊" letter at the end of string to make VS2012 happy, otherwise VS will generate errors  
    // like "Error 3 error C2146: syntax error : missing ‘)‘ before identifier ‘label‘"; 
    TTFConfig ttfConfig("fonts/HKYuanMini.ttf",28,GlyphCollection::CUSTOM, "美好的一天啊");
    auto label = Label::createWithTTF(ttfConfig,"美好的一天啊", TextHAlignment::CENTER, size.width);      
    
  • VS2012显示中文,3.x的做法

    auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/strings.xml");
    std::string chinese  = strings["chinese1"].asString();
    
  • Label 对齐方式

    _label->setAlignment(TextHAlignment);
    //TextHAlignment::LEFT,TextHAlignment::RIGHT,TextHAlignment::CENTER
    
  • 边框发亮,轮廓颜色

    label1->enableGlow(Color4B::YELLOW);   
    
    label3->enableOutline(Color4B::BLUE);    
    
  • 阴影,及位置改变

    shadowLabelTTF->enableShadow(Color4B::BLACK);
    shadowLabelTTF->enableShadow(Color4B::BLACK,offset);   
    
  • 修改行间距

    setLineHeight(float height)
    
  • 修改字间距

    setAdditionalKerning(float space)    
    

转载请注明出处:helkyle.tk

查看3.x NewLabelApi 笔记

标签:3.x   cocos2dx   label   自适应   api   

原文地址:http://blog.csdn.net/joueu/article/details/41909631

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!