CCLableIBMFont 操作文本中单个字符

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()) );


截图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值