cocos2d-x3.0输入框

我要实现很简单的像下面的东东:


左边的是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);

createMyEditBox函数是我订制的一个函数,因为很多东西一样,避免重复代码。

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;
}

效果是上图。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值