cocos2d-x 3.x LabelAtlas类(图片文字)

来源:互联网 发布:知乎 梁湖清 编辑:程序博客网 时间:2024/05/24 01:32


1. 使用实例如下:

/*** 参数1:选择图片中的哪个文字,** 参数2:图片(使用texturePacker制作的文字集合),** 参数3、4:单个文字的宽、高** 参数5:起始的文字** 注意:程序内部按照ASCII码的顺序进行偏移来截取字符的,没有相应字符,也要预留位置    */LabelAtlas* lbSprite = LabelAtlas::create("6", "4_text.png", 30, 48, '1');lbSprite->setAnchorPoint(Vec2(0, 0));lbSprite->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));this->addChild(lbSprite);


---------------------------------------

2. 使用texturePacker拼接LabelAtlas小图片(用在LabelAtlas中的原图片)

【参考http://www.cnblogs.com/meteoric_cry/p/3594185.html


需要勾选的选项:

1. Layout栏:Algorithm项选用Basic (默认的是MaxRects)-> Sort By [Name];

2. Layout栏:设置默认的Border padding、Shape Padding为0;

3. Layout栏:Trim mode项选择None;

4. Geometry栏:Size constraints项选Any size;

5. 选择输出(Output)选项中的,Image format,为RGBA4444,并选择Dithering为 抖动 + 通道(FloydSteinberg + Alpha);

*图片的名称进行控制(它是字符串比较,所以10.png 在 2.png之前,统一使用二位02.png、10.png就可以实现真正的排序)

-------------------------------------------------------------------------------

现在使用的版本是cocos2d-x 3.6,官方示例中已经推荐使用Label类进行创建了(Label中的charmap)

贴点代码参考一下:

pTime = time;/*Label_char_map测试*/label = Label::createWithCharMap("fonts/count.png", 33, 50, '0');label->setAnchorPoint(Vec2(0,0));label->setPosition(Vec2(0, 0));label->setOpacity(200);this->addChild(label);schedule(schedule_selector(GameTimer::update));

void GameTimer::update(float delta){pTime -= delta;char* mtime = new char[10];//此处只是显示分钟数和秒数  自己可以定义输出时间格式sprintf(mtime, "%02d : %02d", (int)pTime / 60, (int)pTime % 60);//sprintf(mtime, "%2.2f Test", pTime);//sprintf(mtime, "%06d", (int)pTime);label->setString(mtime);}



0 0
原创粉丝点击