我要实现很简单的像下面的东东:
左边的是LabelTTF,右边用EditBox。这里有个建议,大家写代码的就不要再用CC前缀的,有命名空间了还用那玩意干毛呢。。。纯粹是cocos2d-x作者仿制的cocos2d的不好的东东。
好,下面写代码了:
CCDictionary *strings = CCDictionary::createWithContentsOfFile("word.xml"); const char *keyWordsFind = ((String*)strings->objectForKey("KeyWordsFind"))->getCString(); const char *suarAyaFind = ((CCString*)strings->objectForKey("SuarAyaFind"))->getCString(); auto labelKeywordFind = LabelTTF::create(keyWordsFind, "Arial", 24); labelKeywordFind->setPosition( ccp(labelKeywordFind->getContentSize().width/2 , visibleSize.height - 50) ); addChild(labelKeywordFind, 1); auto labelSuraAyaFind = LabelTTF::create(suarAyaFind, "Arial", 24); labelSuraAyaFind->setPosition( ccp(labelSuraAyaFind->getContentSize().width/2, visibleSize.height - 100) ); labelSuraAyaFind->setAnchorPoint(ccp(0.5,0.5)); addChild(labelSuraAyaFind, 1); auto keyWordFindBox = createMyEditBox("test.png", CCSizeMake(200, 30), ccp(labelKeywordFind->getContentSize().width+100, visibleSize.height - 50) ); auto suraAyaFindBox = createMyEditBox("test.png", CCSizeMake(200, 30), ccp(labelSuraAyaFind->getContentSize().width+100, visibleSize.height - 100) ); addChild(keyWordFindBox, 1); addChild(suraAyaFindBox,1);
EditBox* HelloWorld::createMyEditBox( std::string spriteFolder,Size& size, Point& position ) { CCScale9Sprite* sacel9Spr = CCScale9Sprite::create(spriteFolder.c_str()); auto box = CCEditBox::create(size, sacel9Spr); box->setPosition(position); box->setFontColor(ccc3(255, 228, 173)); box->setInputMode(kEditBoxInputModeAny); box->setInputFlag(kEditBoxInputFlagInitialCapsWord); box->setFont("Arial", 24); return box; }