Knickknacks cocos2d 使用中的一些琐碎技术点

该文档会不定时更新,也是自己工作终于到问题的积累,谢谢您的关注~~

A:使用ccarry 管理 node 的所有子节点

CCNode* mainmenu = this->getChildByTag(4);
CCArray* temp = mainmenu->getChildren();
((CCMenuItemImage *)temp->objectAtIndex(0))->setEnabled(true);


B: 使用图片创建

//添加平铺的背景
CCSize winSize = CCDirector::sharedDirector()->getWinSize();//获得屏幕尺寸,这里要画个和屏幕等大的静态背景
CCRect r(0, 0, winSize.width, winSize.height);
CCSprite* shelfBG = CCSprite::create("mogu.png", r);// 创建sprite纹理指定循环图片,大小等同屏幕
ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT,GL_REPEAT};// 主要用到的是这个,水平重复平铺,垂直重复平铺
shelfBG->getTexture()->setTexParameters(&tp);
shelfBG->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(shelfBG);// 添加sprite节点到layer
tip: 这里的图片必须是 2的n次方  X 2的n次方


C: 使用定时器 

 

 schedule(schedule_selector(LabelAtlasTest::step));     
void LabelAtlasTest::step(float dt){}

D:  执行完一些列动作回调某个函数

 

CCActionInterval* fade = CCFadeOut::create(1.0f);
    CCActionInterval* fade_in = fade->reverse();
    CCCallFunc* cb = CCCallFunc::create(this, callfunc_selector(LabelAtlasColorTest::actionFinishCallback));
    CCSequence* seq = CCSequence::create(fade, fade_in, cb, NULL);
    CCAction* repeat = CCRepeatForever::create( seq );

E:  可以使用如下方法获取到 CCLabelBMFont  中的单个字符

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


F: 可以从xml 文件中读取字符串变量的值

 

CCDictionary *strings = CCDictionary::createWithContentsOfFile("fonts/strings.xml");
    const char *chinese = ((CCString*)strings->objectForKey("chinese1"))->m_sString.c_str();
    const char *japanese = ((CCString*)strings->objectForKey("japanese"))->m_sString.c_str();
    const char *spanish = ((CCString*)strings->objectForKey("spanish"))->m_sString.c_str();

G: 执行完动作 的三种函数调用

    CCFiniteTimeAction*  action = CCSequence::create(
        CCPlace::create(ccp(200,200)),
        CCShow::create(),
        CCMoveBy::create(1, ccp(100,0)),
        CCCallFunc::create(this, callfunc_selector(ActionSequence2::callback1)),   //无参数
        CCCallFuncN::create(this, callfuncN_selector(ActionSequence2::callback2)),<span style="white-space:pre">	</span>//一个参数
        CCCallFuncND::create(this, callfuncND_selector(ActionSequence2::callback3), (void*)0xbebabeba),  //两个参数
        NULL);

H: 输入框字符串的处理

if (strlen(pkPasswordInputBox->getText()) == 0)   //如果为空…………


    

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值