cocos2d-x 3.x LabelAtlas类(图片文字)
??
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); }
??
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |