CCLableIBMFont 内部采用的是 CCSpriteBatchNode来渲染图片的。使用该控件需要提供一个字体文件.fnt,并且要有对应文件名的png。
例子:
// Upper Label
CCLabelBMFont *label = CCLabelBMFont::create("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt");
addChild(label);
CCSize s = CCDirector::sharedDirector()->getWinSize();
label->setPosition( ccp(s.width/2, s.height/2) );
label->setAnchorPoint( ccp(0.5f, 0.5f) );
//获取文本中的单个字符
CCSprite* BChar = (CCSprite*) label->getChildByTag(0);
CCSprite* FChar = (CCSprite*) label->getChildByTag(7);
CCSprite* AChar = (CCSprite*) label->getChildByTag(12);
CCActionInterval* rotate = CCRotateBy::create(2, 360);
CCAction* rot_4ever = CCRepeatForever::create(rotate);
CCActionInterval* scale = CCScaleBy::create(2, 1.5f);
CCActionInterval* scale_back = scale->reverse();
CCSequence* scale_seq = CCSequence::create(scale, scale_back,NULL);
CCAction* scale_4ever = CCRepeatForever::create(scale_seq);
CCActionInterval* jump = CCJumpBy::create(0.5f, CCPointZero, 60, 1);
CCAction* jump_4ever = CCRepeatForever::create(jump);
CCActionInterval* fade_out = CCFadeOut::create(1);
CCActionInterval* fade_in = CCFadeIn::create(1);
CCSequence* seq = CCSequence::create(fade_out, fade_in, NULL);
CCAction* fade_4ever = CCRepeatForever::create(seq);
//操作单个字符,并给出不同的动作
BChar->runAction(rot_4ever);
BChar->runAction(scale_4ever);
FChar->runAction(jump_4ever);
AChar->runAction(fade_4ever);
// Bottom Label
CCLabelBMFont *label2 = CCLabelBMFont::create("00.0", "fonts/bitmapFontTest.fnt");
addChild(label2, 0, kTagBitmapAtlas2);
label2->setPosition( ccp(s.width/2.0f, 80) );
CCSprite* lastChar = (CCSprite*) label2->getChildByTag(3);
lastChar->runAction( (CCAction*)(rot_4ever->copy()->autorelease()) );
截图: