该文档会不定时更新,也是自己工作终于到问题的积累,谢谢您的关注~~
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) //如果为空…………