在Cocos2d-x的TestCpp工程中有这样一个效果,来自LabelTest
效果图:
控制指定位置上的字符执行一个动作。
通过Label的getChildByTag(idx)可能获取到指定位置上的字符,索引0表示第1个字符,返回的字符是一个CCSprite,这样就可以控制指定位置的字符执行的动作了。
实现代码:
// 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);